【发布时间】:2015-02-18 21:05:27
【问题描述】:
我设法使用以下代码显示带有简码的comment_form(同时将其从默认位置删除):
`add_shortcode( 'wpse_comment_form', function( $atts = array(), $content = '' )
{
if( is_singular() && post_type_supports( get_post_type(), 'comments' ) )
{
ob_start();
comment_form();
print( '<style>.no-comments { display: none; }</style>' );
add_filter( 'comments_open', '__return_false' );
return ob_get_clean();
}
return '';
}, 10, 2 );
birgire 在此答案中建议的代码:https://wordpress.stackexchange.com/a/177289/26350
为了更清楚,这里是我想要得到的地方:我需要通过简码在不同的位置显示 cmets 表单和 cmets 列表。我设法模仿上面相同的代码来显示 cmets_template (后来编辑 cmets.php 以从中删除 comment_form,因为我真正需要显示的是 cmets 列表)但 cmets 列表显示 2x,一个在短代码中位置以及帖子底部(默认位置)。我尝试使用相同的代码独立显示 wp_list_cmets 但没有成功。
【问题讨论】:
标签: php wordpress comments shortcode