我在wordpress中创建一个只包含一个页面的站点(index.php)。页面的每个部分循环并从某个帖子(基于其ID)引入内容。一个部分还有一个评论框以及帖子内容,以及发布的评论。但是,我遇到的问题是,一旦发布了评论(点击发送按钮),它就会加载single.php。这个想法是网站上没有永久链接,只显示帖子的内容,因此只保留用户在索引页面上。我需要添加什么样的代码,以便发布注释不会加载single.php,因此会重新加载index.php?
感谢。
编辑: 只是举一个我正在使用的代码示例: 在index.php我正在使用:
<?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(); ?>
并在我想要评论框的部分:
<?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(); ?>
我打电话给我的评论模板(comments.php)的代码是:
<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 -->
答案 0 :(得分:0)
对onLoad使用jQuery和AJAX,从PHP函数中提取所有注释数据(可能是名称,日期和注释?)。您可能会使用GET请求,但如果您想要使用日期过滤器,则可以使用POST请求并将过滤器作为参数传递。您正在有效地制作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 i = 0;
var leg = $(comment).length;
while (i < leg) {
$("#comments").append("<div>" + comment[i] + "</div>");
i = i + 1;
}
});
&#13;
PHP:
echo json_encode($ arr);
$ arr在其中有你的评论