One-page WordPress site with comment box

I am creating a site in Wordpress that only consists of one page (index.php). Each section of the page loop and contains content from a specific post (based on its ID). One section also has a comment box as well as post content as well as posted comments. However the problem is that after the comment is posted (submit button is clicked) single.php is loaded. The idea is that there are no permalinks on the site and only the post content is displayed, so only the custom page is supported. What code of code do I need to add so that posting a comment does not load single.php and therefore reload index.php?

Thank.

Edit: To give an example of the code I'm using: On index.php, I'm 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 in the section I want a comment 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 for my comments template (comments.php) that I am calling:

<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 is a call back to a function in functions.php ?>
</div>  <!-- //commentBoxesWrap -->

      

+3


source to share


1 answer


Use jQuery and AJAX for onLoad, pull all comment data (presumably name, date and comment?) From any PHP function. You would probably use a GET request, but if you want to have date filters, you must use a POST request and pass the filters as arguments. You are creating an API efficiently.

JQuery

$.ajax({
			    type: "POST",
			    url: "http://example.com/comment-load.php",
			    data: {
			        date: filter_date,
			        tag: filter_tag
			    },
			    dataType: "json"
			})
			    .done(function (comment) {
			    var i = 0;
			    var leg = $(comment).length;
			    while (i < leg) {
			        $("#comments").append("<div>" + comment[i] + "</div>");
			        i = i + 1;
			    }
  });  
      

Run code




And PHP:

echo json_encode ($ arr);

$ arr contains your comments

0


source







All Articles