我的博客网站http://unlieusurterre.fix-it-buddy-clients.com/blog/出现了问题,如果您将精选图片悬停在帖子上,则显示标题,发布像计数和评论一样,但问题是我无法显示我博客帖子的评论数量: - (这是我的博客文章的代码,任何帮助都是谢谢你。: - )
<div id="blog-item" class="span3 post blogitem">
<div class="img">
<a href="<?php echo get_permalink( ) ?>">
<?php if(get_post_meta($post->ID, "ad_post_video", true) ) {
echo '<div class="video2">';
echo stripslashes(get_post_meta($post->ID, "ad_post_video", true));
echo '</div>';} else { ?>
<?php if ( has_post_thumbnail() ) {
the_post_thumbnail('Blog Pic');
} else echo '<img src="'. get_template_directory_uri()
.'/img/no-img.jpg"
alt="Placeholder" />'; ?>
<?php }; ?></a> <a href="<?php echo get_permalink() ?>"
class="mask"></a></div>
<div class="text">
<h6><a href="<?php echo get_permalink() ?>">
<?php the_title(); ?></a></h6>
<?php// custom_excerpt('regular') ?>
<?php if(function_exists('like_counter_p'))
{ like_counter_p('text for like'); }?>
<span style="color:white;"><i class="icon-comment"></i>
<?php echo $comments_count->approved ?>comments</span>
<div class="author-byline"> <i class="icon-pencil"></i>
<h7><?php echo get_the_author_link(); ?></h7>
<div class="pull-right"><i class="icon-calendar"></i>
<?php the_time('F jS') ?>
</div>
</div>
</div>
</div>
答案 0 :(得分:3)
Wordpress Codex非常有用,值得一看。
<?php comments_number( 'text to show for zero comments', 'text to show for one
comment', 'text to show for more comments' ); ?>
文档:http://codex.wordpress.org/Function_Reference/comments_number
更新:必须在The Loop中调用上面的函数。
外循环你可以使用:
<?php $thepost = $post->ID;
$comment_count = $thepost->comment_count;
echo $comment_count;
?>
答案 1 :(得分:0)
我得到了我的问题的答案:-)只是得到评论号码,它的工作宽度我的网站感谢您的帮助人员
<?php wp_count_comments( post_id ); ?>
<span style="color:white;"><i class="icon-comment"></i>
<?php echo $comments_count->approved ?>
<?php echo $my_var ?>
comment/s</span>