这很容易做到。将此代码放入functions.php 文件
逻辑很简单。
获取所有帖子get_posts()
.迭代所有帖子,提取当前帖子的评论数和永久链接,并打印结果。
add_action( \'init\', \'get_comments_count\' ); // Hook to init, elsewhere or use directly in your code
function get_comments_count() {
$all_posts = get_posts( array( \'numberposts\' => -1 ) );
foreach( $all_posts as $current_post ){
$comments_count = get_comment_count( $current_post->ID );
$permalink = get_permalink( $current_post->ID );
printf( \'<a href="%s">%s</a> - %s<br>\', $permalink, $permalink, $comments_count[\'total_comments\'] );
}
}