[英]Show comments on the category page in wordpress
我正在尝试使用comments_template()标记在我的类别页面上的每个帖子之后显示内嵌评论。
但是,由于某种原因,注释或注释表单未显示。 同一标签在单个内容页面上可以正常工作。
顺便说一下,我正在使用WP 3.2.1和21个主题。
comments_template以代码开头:
if ( !(is_single() || is_page() || $withcomments) || empty($post) )
return;
因此仅适用于帖子和单个页面。
您可以创建一个列出类别的页面,也可以使用comments_template。 或使用get_comments获取帖子的所有评论,然后手动循环浏览它们并生成输出。 您还可以设置全局变量$ withcomments,请参见sbrajesh的答案。
可以通过强制加载注释来实现。 您可以通过设置全局变量'$ withcomments'来强制加载评论
例如,您可以将此代码放入您的functions.php中
add_filter('wp_head','sb_force_comment');
function sb_force_comment( ) {
global $withcomments;
if(is_category())
$withcomments = true; //force to show the comment on category page
}
如果您在类别页面上使用comments_template(),它将在类别页面上显示评论以及表单。
如果您不想在类别页面上显示注释表单,可以通过将以下代码放入您的functions.php中来实现。
add_filter('comments_open','sb_fake_comments_closed_on_category',20,2);
function sb_fake_comments_closed_on_category ($is_open,$post_id){
if(is_category())
return false;
return $is_open;
}
希望能帮助到你 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.