VIP会员:免费下载(VIP 特惠:36元/月、129元/年)。
非VIP用户:付费后仅限单次下载,请仔细阅读 服务购买须知。
在循环外调用WordPress文章评论数
function add_comment_count_to_posts() {
global $wpdb, $post;
$id = $post->ID;// 文章ID
$comment_count = $wpdb->get_var( "SELECT comment_count FROM $wpdb->posts WHERE post_status = 'publish' AND ID = $id" );// 获取文章评论数
$comment_status = $wpdb->get_var( "SELECT comment_status FROM $wpdb->posts WHERE ID = $id" );// 文章是否开启了评论
$html = '<div class="comment-popup">';
$html .= '<span>';
$count = '';
if( $comment_status == 'open' ) {
$count = $comment_count;
} else {
$count = '评论关闭';
}
$html .= $count . '</span></div>';
return $html;
}
获取某文章最新一条评论日期:
$comment_args = array(
'post_id' => get_the_ID(),
'number' => 1,
);
$latest_comment = get_comments($comment_args);
echo $latest_comment[0]->comment_date;
© 版权声明
NOTICE
01
DISCLAIMER
本站分享的WordPress主题/插件均遵循GPLv2 许可协议(开源软件),版权归原作者所有。如果有侵犯到您的权益,请与我们联系,将第一时间处理。
02
VIP PRIVILEGE
遇到付费内容?升级终身VIP即可全站免费畅享所有资源,自助开通会员或联系客服进行人工开通。
聊天 QQ 群:461848201
THE END








暂无评论内容