簡體   English   中英

用戶沒有帖子時如何顯示WordPress author.php?

[英]How to show WordPress author.php when user has no posts?

因此,我一直在建立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(); ?>

如果有問題的用戶對他/她的名字任何帖子,那就很好。 但是,當他們的帖子為零時,個人資料頁面的空白處應該有內容。

我該如何克服?

僅供參考,完整author.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; ?>

`

您不能自行查詢嗎?

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

您將整個頁面內容包裝在條件中:

if ( have_posts() ) :

如果用戶沒有帖子,那將是有原因的,它跳到底部並且什么也不顯示...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM