3
我在wordpress中只创建一个网站(index.php)。页面的每个部分循环并从某个帖子中引入内容(基于其ID)。其中一部分还有一个评论框以及发布内容以及发布的评论。但是,我遇到的问题是,一旦发布了评论(点击发送按钮),就会加载single.php。这个想法是,网站上没有固定链接,只显示了帖子的内容,因此只能将用户保留在索引页上。我需要添加什么样的代码才能发布评论不会加载single.php,因此会重新加载index.php?单页WordPress网站与评论框
谢谢。
编辑: 只给我使用的代码示例: 上的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 -->
使用AJAX您的意见?提供关于你的代码的更多细节,如何发布评论? – sinhayash
那个评论框是你写的一个插件吗? –
sinhayash是对的:你需要使用jquery/ajax(http://api.jquery.com/jquery.post/)。是否有人点击提交按钮,ajax会调用single.php(?)来保存文章并发回内容或格式化的html - 这个信息可以用jquery append(http://api.jquery .com/append /) – WebDevel