在循环外调用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;
糖果博客,原文地址https://wpocn.com/4292.html
© 版权声明
版权声明
1
本站名称:糖果博客
2
本站网址:wpocn.com
3
本网站的内容来源于网络,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4
本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5
本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报。
6
本站附件资源、教程等内容如因时效原因失效或不可用,请评论区留言或联系站长及时更新。
THE END













暂无评论内容