[英]Display comments inside a loop of custom post type in page
I am trying to add a comments form and list using comments_template()
to a loop of custom post type. 我正在尝试使用comments_template()
向自定义帖子类型的循环添加评论表单和列表。 This loop is displayed inside a page. 此循环显示在页面内。
The idea is to have a tips page with a list of tips (each tip should be a new post so for that I created a custom post type tips ) 想法是创建一个包含提示列表的提示页面(每个提示应该是一个新帖子,因此我创建了一个自定义帖子类型的提示 )
Inside each tip should be a list of comments with a comment form. 每个提示内应有带有评论表格的评论列表。 this comments form is general and applies to multiple post types (they behave regularly). 此评论表是一般性的,适用于多种帖子类型(它们的行为举止定期)。
I looked inside the comments_template()
function and found this condition that prevents the usage of the function properly: 我查看了comments_template()
函数内部,发现这种情况阻止了该函数的正确使用:
if ( !(is_single() || is_page() || $withcomments) || empty($post) )
return;
This is not the code I use, but this is the idea: 这不是我使用的代码,而是这个主意:
// page.php
get_header();
while ( have_posts() ) {
the_post();
/**
* The arguments are created based on the data stored in the settings for this page
*/
query_posts($args);
if(have_posts()) {
while ( have_posts() ) {
the_post();
comments_template(); // This won't work
}
}
}
get_footer();
Here are the settings for the post type: 这是帖子类型的设置:
array(
$labels,
'publicly_queryable' => true,
'has_archive' => false,
'menu_position' => 30,
'menu_icon' => 'dashicons-lightbulb',
'supports' => array('title', 'author', 'editor', 'revisions', 'comments')
)
ideas on how to make it work? 如何使它起作用的想法?
http://danielpowney.com/docs/wp-comments-integration/ http://danielpowney.com/docs/wp-comments-integration/
Check 'Post Type Support' near the bottom first then the other solutions if comments are already supported for your CPT 首先检查底部附近的“帖子类型支持”,然后检查其他解决方案(如果您的CPT已支持注释)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.