正在查看 1 个帖子:1-1 (共 1 个帖子)
-
作者帖子
-
还是为博客互动活跃度考虑,显示效果如下
function get_author_comments_count( $atts ) { global $wpdb; $author_id = get_post_field( 'post_author' ); // 获取当前文章作者 ID $comments_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE user_id = %d AND comment_approved = %d", $author_id, 1 ) ); $replies_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->comments} WHERE user_id = %d AND comment_approved = %d AND comment_parent != %d", $author_id, 1, 0 ) ); $output = " 作者共有 {$comments_count} 条评论和 {$replies_count} 条回复"; return $output; } add_shortcode( 'author_comments_count', 'get_author_comments_count' );
在文章中使用 [author_comments_count] 简码即可。
-
作者帖子
正在查看 1 个帖子:1-1 (共 1 个帖子)
- 哎呀,回复话题必需登录。