WordPress的没有显示每条帖子的评论数量
问题描述:
所以即时通讯试图让wordpress循环与每个帖子的评论显示数量。我只想从一个类别的职位。循环正在工作,但评论数量不正确。在每一篇文章中,它只是说没有评论(即使我有10个或更多的评论)WordPress的没有显示每条帖子的评论数量
<?php
$query = new WP_Query('category_name=blog&post_type=post');
if ($query->have_posts()) :
?>
<?php
// Start the loop.
while ($query->have_posts()) : $query->the_post();
?>
<div class="col-12 col-md-6 blog_single_homepage">
<div class="col-12">
<div class="row align-items-end">
<div class="col-5 col-md-3 autor_section">
<?php echo get_avatar(get_the_author_meta('user_email'), '150', $default, $alt, array('class' => array('rounded-circle'))); ?>
</div>
<div class="col-7 col-md-9 autor_info">
<a href="<?php echo get_author_posts_url(get_the_author_meta('ID'), get_the_author_meta('user_nicename')); ?>" class="autor_name"><?php the_author(); ?></a>
<span class="align-middle"><?php the_time('d/m/Y'); ?></span>
<div class="cat">
<p><?php the_category(', '); ?></p>
</div>
<hr>
</div>
</div>
</div>
<div class="col-12 blog_content_short">
<a href="<?php the_permalink(); ?>">
<h3><?php the_title() ?></h3>
<p><?php echo wp_trim_words(get_the_content(), 50); ?></p>
<div class="read_more_over">
<div class="title_inner">
<?php the_title() ?>
</div>
<div class="inner_show">
Read more
</div>
</div>
</a>
<div class="comments">
<?php
printf(_nx('One Comment', '%1$s Comments', get_comments_number(), 'comments title', 'textdomain'), number_format_i18n(get_comments_number()));
?>
</div>
</div>
</div>
<?php
// End the loop.
endwhile;
else :
echo 'No blog posts...';
endif;
?>
答
您的代码正常工作。请确认评论已被批准。此代码不显示尚未批准的评论。如果你想要所有评论的细节,请使用wp_count_comments
。这返回每个状态的评论详情:在这里查看更多详情:https://codex.wordpress.org/Function_Reference/wp_count_comments
http://imgur.com/a/SWbW1:S我有超过400多个批准的评论:我只是不明白它 – NoobyAFK
'$ comments_count = wp_count_comments(); var_dump($ comments_count);''你可以尝试在你的代码的'printf(_nx ...'行之前添加它。“ –
object(stdClass)#1237(7){[”approved“] => string(3)”403 “[”spam“] => int(0)[”trash“] => int(0)[”post-trashed“] => int(0)[”total_comments“] => int(415)[”all “] => int(415)[”moderated“] => string(2)”12“} 0注释 – NoobyAFK