2012-02-22 62 views
0

這是我第一次在這裏發表一個問題,這是一個寶貴的資源之前,所以我想也許有人能夠回答我的問題。php if statement not evaluation properly

這可能是一個簡單的解決方案,但正如我已經說過,我是一個PHP noob。原諒我。

這裏是我的代碼:

<?php wp_reset_postdata(); // reset the query ?> 
<?php $authorposts = get_the_author_posts(); 
    if ($authorposts < 1) { 
    echo " "; 
    } 
    else { ?> 
<div class="single-sidebar"><!--expert_blog start--> 
    <div class="single-sidebar-middle"> 
    <div class="single-sidebar-top"> 
    <h3>More Posts by <?php the_author();?></h3> 
    </div> 
    <p><?php echo get_related_author_posts(); ?></p> 
    <div class="single-sidebar-bottom"> 
     <div class="more_blog"><a href="<?php echo get_author_posts_url(get_the_author_meta('ID')); ?>">+ Read more</a></div> 
    </div> 
    </div> 
</div> 
<div class="clear"></div> 
<?php wp_reset_postdata(); // reset the query ?> 

什麼,這是應該做的:特定作者獲得職位的數量(目前正在瀏覽的帖子),並輸出到一個有條件的聲明說,如果它是1或小於1,什麼也不顯示。否則,顯示每篇文章的標題。

發生了什麼事情:即使只有一篇帖子提交給作者,但是沒有任何內容顯示在列表中(即時猜測,因爲只有一篇文章,並且您已經在查看它)。

任何幫助將不勝感激,它已經晚了,我的大腦已經融化。請讓我知道是否有任何需要澄清。

在此先感謝。

回答

1

相反的if ($authorposts < 1)應該if ($authorposts <= 1)

+0

哦男人...謝謝! – emerisch 2012-02-24 21:29:33