0

我正在为 Wordpress 使用 Bones

如何在主索引的文章页脚中显示评论计数(带有指向单个帖子页面上评论的链接)?

4

2 回答 2

0

您的意思是网站评论总数还是每个特定帖子都有评论数以及它显示在索引页面上?不太确定返回 wp_count_comments(); 或列出的 wp_list_comments('type=comment&callback=bones_comments'); comments.php 文件中的函数。(不要直接加载)

我过去用过自己的:

function get_comments_number( $post_id = 0 ) {
    $post_id = absint( $post_id );

    if ( !$post_id )
        $post_id = get_the_ID();

    $post = get_post($post_id);
    if ( ! isset($post->comment_count) )
        $count = 0;
    else
        $count = $post->comment_count;

    return apply_filters('get_comments_number', $count, $post_id);
}

否则,您可以将 WP 函数添加到循环中,以将其添加到每个帖子的输出中。

wp_count_comments( post_id );
于 2013-08-07T23:44:59.380 回答
0

您只需关注即可获取帖子的评论数

<?php echo $my_var = get_comments_number( $post_id ); ?> 

您可以通过在索引页面的循环内使用来获取它

也跟随将引导你一个帖子的单页

 <a class="your-class" href="<?php the_permalink(); ?>"> Read more</a>
于 2013-08-08T04:30:50.413 回答