2012-10-12 26 views
1

好吧,我在我的一個網站上有一個關於頁面的頁面,列出了作者,他們的最後一篇文章以及與他們聯繫的方式。Wordpress頁面模板php不按預期輸出

我有一些PHP來做到這一點。然而,我們有3位作者,它顯示了4.它顯示的第一個結果是第二和第三位作者的組合。我想弄清楚如何顯示真正的3位作者。

http://oi50.tinypic.com/mwfexj.jpg紅色的邊界作者是不應該在那裏的作者。注意它有來自作者2和3的數據?

 <?php 
    $authors = $wpdb->get_results('SELECT DISTINCT post_author FROM '.$wpdb->posts); 
    if($authors): 
    foreach($authors as $author): 
    ?> 

    <div class='author' id='author-<?php the_author_meta('user_login', $author->post_author); ?>'> 
     <h3><?php the_author_meta('display_name', $author->post_author); ?></h3> 

     <?php if(get_the_author_meta('description', $author->post_author)): ?> 
     <div class='description'> 
      <?php echo get_avatar(get_the_author_meta('user_email', $author->post_author), 80); ?> 
      <p><?php the_author_meta('first_name', $author->post_author); ?> <?php the_author_meta('description', $author->post_author); ?></p> 
     </div> 
     <?php endif; ?> 

     <?php 
     $recentPost = new WP_Query('author='.$author->post_author.'&posts_per_page=1'); 
     while($recentPost->have_posts()): $recentPost->the_post(); 
     ?> 
     <h4>Recent Post: <a href='<?php echo get_permalink();?>'><?php the_title(); ?></a></h4> 
     <?php endwhile; ?> 

     <?php if(get_the_author_meta('twitter', $author->post_author) || get_the_author_meta('facebook', $author->post_author) || get_the_author_meta('aim', $author->post_author) || get_the_author_meta('url', $author->post_author) || get_the_author_meta('sitename', $author->post_author)): ?> 
     <ul class='connect'> 
      <?php if(get_the_author_meta('url', $author->post_author)): ?> 
      <li><a href='<?php the_author_meta('url', $author->post_author); ?>' class="website"><?php the_author_meta('sitename', $author->post_author); ?></a></li> 
      <?php endif; ?> 

      <?php if(get_the_author_meta('aim', $author->post_author)): ?> 
      <li><a href='aim:goim?screenname=<?php the_author_meta('aim', $author->post_author); ?>' class="aim"><?php the_author_meta('aim', $author->post_author); ?></a></li> 
      <?php endif; ?> 

      <?php if(get_the_author_meta('twitter', $author->post_author)): ?> 
      <li><a href='http://twitter.com/<?php the_author_meta('twitter', $author->post_author); ?>' class="twitter">Twitter</a></li> 
      <?php endif; ?> 

      <?php if(get_the_author_meta('facebook', $author->post_author)): ?> 
      <li><a href='http://www.facebook.com/<?php the_author_meta('facebook', $author->post_author); ?>' class="facebook">Facebook</a></li> 
      <?php endif; ?> 

     </ul> 
     <?php endif; ?> 
    </div> 
    <?php endforeach; endif; ?> 

回答

0

檢查你的數據庫,你可能有第四作者出現,如果沒有,空表,並添加新的作者

+0

我檢查了數據庫。只有3個用戶駐留在它。清空表格是不可能的,因爲它是一個既定的網站。然而,我玩弄了查詢並得到了一些奇怪的結果。我隨心所欲地刪除了DISTINCT,它給了我無盡的作者循環。我還重寫了這個查詢,它只給我3位作者,但是這是錯誤的,一位作者被複制,並且沒有向我展示最後一位作者。 –