首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Wordpress页面模板php未按预期输出

问Wordpress页面模板php未按预期输出
EN

Stack Overflow用户
提问于 2012-10-12 12:36:39
回答 1查看 180关注 0票数 1

好的,我在我的一个网站上有一个关于作者的页面,列出了作者,他们的最后一篇文章以及与他们联系的方式。

我有一些PHP来做这件事。然而,我们有3个作者,它显示了4个。它显示的第一个结果是第二个和第三个作者的组合。我想知道如何只显示真实的3位作者。

http://oi50.tinypic.com/mwfexj.jpg,红色边框的作者是不应该出现在那里的。注意到它有来自作者2和3的数据吗?

代码语言:javascript
复制
        <?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; ?>
EN

回答 1

Stack Overflow用户

发布于 2012-10-12 13:21:08

检查您的数据库,可能有第四个作者,如果没有,请清空该表并添加新的作者

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12852340

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档