首先把帖子ID写出
[comments ID="1"]
然后使用下面这段代码就可以实现计数ID1帖子的评论数
function comments_shortcode($atts) {
extract( shortcode_atts( array(
'ID' => ''
),$atts ) );
$num = 0;
$post_ID = $ID;
$querIEd_post = get_post($post_ID);
$cc = $querIEd_post->comment_count;
if( $cc == $num || $cc > 1 ) : $cc = $cc.' Comments';
else : $cc = $cc.' Comment';
endif;
$permalink = get_permalink($post_ID);
return '<a href="'. $permalink . '" class="comments_link">' . $cc . '</a>';
}
add_shortcode('comments','comments_shortcode'); 总结
以上是内存溢出为你收集整理的给 WordPress 博客评论添加计数统计代码全部内容,希望文章能够帮你解决给 WordPress 博客评论添加计数统计代码所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)