2012-10-12 3 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

데이터베이스를 확인, 당신은 거기에 네 번째 저자가 아닌 경우, 빈 테이블 및 I 데이터베이스를 확인 새 저자

+0

을 추가 할 수 있습니다. 3 명의 사용자 만 거주합니다. 테이블을 비우는 것은 확립 된 사이트이기 때문에 의문의 여지가 없습니다. 그러나 쿼리를 가지고 놀고 이상한 결과를 얻었습니다. 희미한 순간에 DISTINCT를 제거하고 나에게 끝없는 반복자를주었습니다. 필자는 또한 쿼리를 다시 작성하고 3 명의 저자 만 보여 주었지만 잘못되었습니다. 한 명의 작성자가 복제되어 마지막 저자가 표시되지 않았습니다. –

관련 문제