我正在修改一个模板文件,该文件循环遍历许多类似于WordPress中的存档页面的帖子。在该输出上,我可以显示使用get_comments和wp_list_comments已经提交的评论。但是,我一生无法获得评论表来输出。我已经尝试过使用args提交page_id的comment_form()的各种变体,但无济于事,我要么中断了页面,要么就没有出现。评论肯定是开放的,可以发表评论,但不会显示在页面上。
comment_form($featuredposts[$articlePageNo]->ID);
不会中断我的页面,但是会以无格式返回。
comment_form(post_id => $featuredposts[$articlePageNo]->ID);
中断页面。 我认为这可能是为了防止在WordPress的非单个页面上显示comment_form,但是我似乎无法隔离如何告诉WordPress在我自己的网站上可以这样做。
comment_form($featuredposts[$articlePageNo]->ID); //ID is the post ID from my loop.
//This works for displaying the already submitted comments:
//Gather comments for a specific page/post
$comments = get_comments(array(
'post_id' => $postIDD,
'status' => 'approve' //Change this to the type of comments to be displayed
));
//Display the list of comments
wp_list_comments(array(
'per_page' => 10, //Allow comment pagination
'reverse_top_level' => false //Show the latest comments at the
top of the list
), $comments);
答案 0 :(得分:0)
comment_form()
实际上将帖子ID作为 second 自变量。 (如果您不提供帖子ID,它将使用当前页面的帖子ID)
因此,尝试将ID作为第二个参数传递:
comment_form(null, $featuredposts[$articlePageNo]->ID);
答案 1 :(得分:0)
所以我找不到这是一个简单的解决方法,四处走动以获取解决方案,但在此处发布我发现的内容,以便将来我知道如何做。最后,我输出一个表格来处理评论。我删除了许多字段,但您会明白的。提交后确实会将您发送到帖子页面,但这又是一天。
<form id="commentform" action="<?php echo get_option('siteurl'); ?>/wp-comments-post.php" method="post" id="commentform">
<div class="commentform-element">
<label class="hide" for="comment"></label>
<textarea id="comment" class="input-fields" name="comment" cols="40" rows="3"></textarea>
</div>
<input name="submit" class="form-submit-button" type="submit" id="submit-comment" value="Post">
<input type="hidden" name="comment_post_ID" value="<?php echo $featuredposts[$articlePageNo]->ID; ?>" id="comment_post_ID">
<input type="hidden" name="comment_parent" id="comment_parent" value="0">
</form>