如何显示循环外每个帖子的评论量?我已经在函数中尝试过了:
\' . get_comments_number . \'
, 但它在屏幕上输出了文本“array”。。。我要怎么做才能让它工作?
在我的single.php
我用它来输出一些列表项(帖子):
<ul class="wow dude">
<?php echo wowPosts(2); ?>
</ul>
在我的职能中。php我使用的是:function wowPosts($num) {
global $wpdb;
$posts = $wpdb->get_results("SELECT comment_count, ID, post_title FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , $num");
foreach ($posts as $post) {
setup_postdata($post);
$id = $post->ID;
$title = $post->post_title;
$count = $post->comment_count;
$comment_count = get_comment_count($post->ID);
$all_comments = get_comment_count( array ( \'post_id\' => get_the_ID() ) );
if ($count != 0) {
$popular .= \'<li>\';
$popular .= \'<a href="\' . get_permalink($id) . \'" title="\' . $title . \'">\' . $title . \'</a> \'. count( $all_comments ) . \' \';
$popular .= \'</li>\';
}
}
return $popular;
}
正如您所看到的,我已经编辑了您的第一个代码并在这个函数中实现了,以便我可以在每个列表项(每个帖子)中使用它。。。它仍然显示到处都是4。