2013-08-19 56 views
1

我買了我的博客網站http://unlieusurterre.fix-it-buddy-clients.com/blog/一個問題,如果你懸停功能的圖像後它顯示的標題,帖子像計數和像計數評論,但問題是我不能展示我的博客文章的評論數:-(這是我的博客文章的代碼的任何幫助都apreciated謝謝。:-)如何獲得的評論數,並把在博客頁面

<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> 
+3

這是*痛苦*閱讀...任何機會,你可以清理它一點? – brbcoding

+4

這個問題似乎是題外話,因爲它屬於上http://wordpress.stackexchange.com/。 –

+0

這很明顯嗎? –

回答

3

WordPress的食品是非常有益的,值得一遊。

<?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

更新:以上功能在循環中被調用。

外循環,可以使用:

<?php $thepost = $post->ID; 
     $comment_count = $thepost->comment_count; 
     echo $comment_count; 
?> 
+0

我得到的概念,我認爲它的帖子頁面內唯一的工作我需要的是我得到一個職位的評論數,顯示它在我的博客頁面http://unlieusurterre.fix-it-buddy-clients.com/blog/ –

+0

是的,它必須在循環中調用。請看我更新的答案。 – eevaa

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>