如何在用户没有帖子时显示WordPress author.php?

时间:2013-09-11 15:13:53

标签: php wordpress profile author

所以我一直在构建author.php页面以显示用户配置文件。

这取决于'if(have_posts()):'在顶部,在哪里 - 仅供参考 - 我也有......

<?php /* Queue the first post, that way we know * what author we're dealing with (if that is the case). * * We reset this later so we can run the loop * properly with a call to rewind_posts(). */ the_post(); ?>

<?php /* Since we called the_post() above, we need to * rewind the loop back to the beginning that way * we can run the loop properly, in full. */ rewind_posts(); ?>

如果有问题的用户任何帖子到他/她的名字,那就没关系了。 但是,当他们没有帖子时,个人资料页面会显示空白,应该有内容。

我怎样才能克服这个?

仅供参考,完整作者.php是......

`

    <?php if ( have_posts() ) : ?>

        <?php
            /* Queue the first post, that way we know
             * what author we're dealing with (if that is the case).
             *
             * We reset this later so we can run the loop
             * properly with a call to rewind_posts().
             */
            the_post();
        ?>

        <?php
            /* Since we called the_post() above, we need to
             * rewind the loop back to the beginning that way
             * we can run the loop properly, in full.
             */
            rewind_posts();
        ?>

        <?php
        /* Get Extra User Fields*/
        $values_by_name = array(  // Assign defaults to all CIMY fields
            'TITLEJOB' => '',
            'TITLESECONDARY' => '',
            'COMPANY' => '',
        );
        $values = get_cimyFieldValue($author, false);
        if ($values) {
            foreach ($values as $value) {
                $values_by_name[$value['NAME']] = cimy_uef_sanitize_content($value['VALUE']);
            }
        }
        ?>

        <h1><?php the_author(); ?></h1>

        <?php
        if(!empty($values_by_name['COMPANY'])) {
            echo '<p>Company: '.$values_by_name['COMPANY'].'</p>';
        }

        if(!empty($values_by_name['TITLEJOB'])) {
            echo '<p>Title: '.$values_by_name['TITLEJOB'].'</p>';

            if(!empty($values_by_name['TITLESECONDARY'])) {
                echo '<p>Secondary: '.$values_by_name['TITLESECONDARY'].'</p>';
            }

        }
        ?>

        <?php

        ?>

        <p><?php echo get_avatar( get_the_author_meta( 'user_email' )); ?></p>
        <p>URL: <a href="<?php the_author_meta( 'user_url' ); ?>"><?php the_author_meta( 'user_url' ); ?></a></p>
        <p>Description: <?php echo nl2br(get_the_author_meta( 'description' )); ?></p>

        <h4>Posts: <?php the_author_posts(); ?></h4>
        <?php /* Start the Loop */ ?>
        <ul>
        <?php while ( have_posts() ) : the_post(); ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
        <?php endwhile; ?>
        </ul>

        <h4>Topics</h4>
        <ul>
            <li>Topic</li>
            <li>Topic</li>
            <li>Topic</li>
        </ul>

        <h4>Companies</h4>
        <ul>
            <li>Company</li>
            <li>Company</li>
            <li>Company</li>
        </ul>

    <?php endif; ?>

`

2 个答案:

答案 0 :(得分:0)

你能不能自己提问?

haveno_posts{

    If Posts = 0 then return true?

}

<?php if ( have_posts() ) : ?>

将是

<?php if ( have_posts() || haveno_posts() ) : ?>

或者:

http://wordpress.org/plugins/show-authors-without-posts/admin/

https://wordpress.stackexchange.com/questions/41078/show-author-archive-pages-for-authors-with-no-posts

答案 1 :(得分:0)

您将整个页面内容包含在条件:

if ( have_posts() ) :

如果用户没有帖子,它会跳到底部并且什么都不显示...