1

Okay, I have an about page on one of my sites that lists the authors, their last post and ways to connect with them.

I have some PHP to do it. However we have 3 authors and it's showing 4. The first result it shows is a combination of the second and third author. I would like to figure out how to only display the 3 authors that are actually real.

http://oi50.tinypic.com/mwfexj.jpg The red bordered author is the one that shouldn't be there. Notice it has data from author 2 and 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; ?>
4

1 に答える 1

0

データベースを確認してください。4 人目の著者がいる可能性があります。そうでない場合は、テーブルを空にして新しい著者を追加してください。

于 2012-10-12T05:21:07.870 に答える