php - Single page WordPress site with comments box -
i creating site in wordpress consists of 1 single page (index.php). each section of page loops , brings in content post (based on id). 1 section has comment box post content, along posted comments. however, problem have once comment has been posted (send button clicked), loads single.php. idea there no permalinks on site , content of posts displayed, hence keeping user on index page only. kind go code need add posting comment not load single.php, , therefore reload index.php?
thanks.
edit: give example of code using: on index.php using:
<?php $category = array('category_name' => 'my category'); ?> <?php query_posts($category); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="articlewrap"> <?php the_content(); ?> </div> <?php endwhile; endif; ?> <?php wp_reset_query(); ?>
and on section want comments box:
<?php $other_category = array('category_name' => 'my other category'); ?> <?php query_posts($other_category); ?> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="articlewrap"> <?php the_content(); ?> <?php $withcomments = 1; comments_template(); ?> </div> <?php endwhile; endif; ?> <?php wp_reset_query(); ?>
the code comments template (comments.php) call in is:
<div class="messagebox"> <?php $comments_args = array( 'comment_notes_after' => '', 'label_submit'=>'submit', 'title_reply' => '', 'logged_in_as' => '', 'comment_field' => '<p class="comment-form-comment"><label for="comment"></label><br /><textarea id="comment" name="comment" aria-required="true"></textarea></p>', ); comment_form($comments_args); ?> </div> <!-- //messagebox --> <div class="commentboxeswrap"> <?php wp_list_comments('type=comment&callback=showcomments'); //this call function in functions.php ?> </div> <!-- //commentboxeswrap -->
use jquery , ajax onload, pull comments data (presumably name, date , comment?) whatever php function is. use request if want have date filters, use post request , pass filters arguments. making api.
jquery:
$.ajax({ type: "post", url: "http://example.com/comment-load.php", data: { date: filter_date, tag: filter_tag }, datatype: "json" }) .done(function (comment) { var = 0; var leg = $(comment).length; while (i < leg) { $("#comments").append("<div>" + comment[i] + "</div>"); = + 1; } });
and php:
echo json_encode($arr);
$arr has comments in it
Comments
Post a Comment