【问题标题】:Wordpress page template php not outputting as expectedWordpress 页面模板 php 未按预期输出
【发布时间】:2012-10-02 20:55:42
【问题描述】:

好的,我的一个网站上有一个关于页面,其中列出了作者、他们的最新帖子以及与他们联系的方式。

我有一些 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; ?>

【问题讨论】:

    标签: php mysql wordpress wordpress-theming


    【解决方案1】:

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

    【讨论】:

    • 我检查了数据库。只有 3 个用户居住在其中。清空表格是不可能的,因为它是一个已建立的站点。然而,我确实玩弄了查询并得到了一些奇怪的结果。我一时兴起删除了 DISTINCT,它给了我无穷无尽的作者循环。我还重写了查询,它只显示了 3 个作者,但这是错误的,一个作者重复了,它没有显示最后一个作者。
    猜你喜欢
    • 2015-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多