如何在Auth.php中显示用户角色

时间:2015-07-05 作者:Yajuvendra

php模板请告诉我如何显示作者角色

<?php
/**
 * The template for displaying Author Archive pages.
 *
 * 
 */
if ( !isset( $_REQUEST[\'rtype\'] ) && $_REQUEST[\'rtype\'] == \'\' ) {
    //This sets the $curauth variable
    if ( isset( $_GET[\'author_name\'] ) ) :
        $curauth = get_user_by( \'login\', $author_name );
    else :
        $curauth = get_userdata( intval( $author ) );
    endif;
    ?>
    <?php get_header(); ?>
    <!--Start Cotent Wrapper-->
    <div class="content_wrapper">
        <div class="container_24">
            <div class="grid_24">
                <div class="grid_17 alpha">
                    <!--Start Cotent-->
                    <div class="content">
                        <?php if ( have_posts() ) : the_post(); ?>
                            <h1><?php printf( __( ATHR_ARC . \' %s\', THEME_SLUG ), "<a class=\'url fn n\' href=\'" . get_author_posts_url( get_the_author_meta( \'ID\' ) ) . "\' title=\'" . esc_attr( get_the_author() ) . "\' rel=\'me\'>" . get_the_author() . "</a>" ); ?></h1>
                            <?php
                            // If a user has filled out their description, show a bio on their entries.
                            if ( get_the_author_meta( \'description\' ) ) :
                                ?>
                                <div id="author-info">
                                    <div class="author-inner">
                                        <div id="author-avatar"> <?php echo get_avatar( get_the_author_meta( \'user_email\' ), apply_filters( \'cc_avatar_size\', 50 ) ); ?> </div>
                                        <!-- #author-avatar -->
                                        <div id="author-description">
                                            <h2><?php printf( __( ABT . \' %s\', THEME_SLUG ), get_the_author() ); ?></h2>
                                            <?php the_author_meta( \'description\' ); ?>

                                    </div>
                                </div>
                                <!-- #entry-author-info -->
                            <?php endif; ?>
                        <?php endif; ?>
                        <?php

                        $limit = get_option( \'posts_per_page\' );
                        $paged = (get_query_var( \'paged\' )) ? get_query_var( \'paged\' ) : 1;
                        query_posts( array(
                            \'post_type\' => POST_TYPE,
                            \'showposts\' => $limit,
                            \'paged\' => $paged,
                            \'author\' => $curauth->ID

                        ) );

                        if ( have_posts() ) :
                            ?>
                            <ul id="products" class="list clearfix">
                                <?php
                                while ( have_posts() ): the_post();
                                    $postimg = get_post_meta( $post->ID, \'cc_image1\', true );
                                    ?>
                                    <!-- row 1 -->
                                    <li class="thumbnail">
                                        <section class="thumbs">
                                            <?php if ( (function_exists( \'has_post_thumbnail\' )) && (has_post_thumbnail()) ) { ?>
                                                <?php cc_get_thumbnail( 78, 78 ); ?>                    
                                            <?php } else { ?>
                                                <?php cc_get_image( 78, 78, \'\', $postimg ); ?> 
                                                <?php
                                            }
                                            $taxonomies = get_the_term_list( $post->ID, CUSTOM_CAT_TYPE, \'\', \',\', \'\' );
                                            ?>
                                            <section class="thumb_item">
                                                <?php if ( get_post_meta( $post->ID, \'cc_price\', true ) !== \'\' ) { ?>
                                                    <span class="price"><?php
                                                        if ( cc_get_option( \'cc_currency\' ) != \'\' ) {
                                                            echo cc_get_option( \'cc_currency\' );
                                                        } else {
                                                            echo get_option( \'currency_symbol\' );
                                                        }
                                                        echo get_post_meta( $post->ID, \'cc_price\', true );
                                                        ?></span>
                                                <?php } ?>
                                                <a class="view" href="<?php the_permalink(); ?>"><?php echo VIEW_IT; ?></a>
                                            </section>
                                        </section>
                                        <section class="contents">
                                            <h6 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h6>
                                            <?php the_excerpt(); ?>
                                            <div class="clear"></div>
                                            <ul class="post_meta">
                                                <li class="estimate"><?php echo human_time_diff( get_the_time( \'U\' ), current_time( \'timestamp\' ) ) . \' \' . AGO; ?></li>
                                                <li class="cate"><?php echo $taxonomies; ?></li>
                                                <li class="author"><?php echo BY; ?>&nbsp;<?php the_author_posts_link(); ?></li>
                                            </ul>

                                        </section>
                                    </li>
                                    <!-- row 1 -->   
                                    <?php
                                endwhile;
                                ?>                                       
                            </ul> 
                            <?php
                        endif;
                        wp_reset_query();
                        cc_pagination();
                        ?>
                        <?php
                        $limit = get_option( \'posts_per_page\' );
                        $paged = (get_query_var( \'paged\' )) ? get_query_var( \'paged\' ) : 1;
                        query_posts( array(
                            \'post_type\' => \'post\',
                            \'showposts\' => $limit,
                            \'paged\' => $paged,
                            \'author\' => $curauth->ID
                        ) );
                        if ( have_posts() ) :
                            ?>
                            <ul id="products" class="list clearfix">
                                <?php
                                while ( have_posts() ): the_post();
                                    $postimg = get_post_meta( $post->ID, \'cc_image1\', true );
                                    ?>
                                    <!-- row 1 -->
                                    <li class="thumbnail">
                                        <section class="thumbs">
                                            <?php if ( (function_exists( \'has_post_thumbnail\' )) && (has_post_thumbnail()) ) { ?>
                                                <?php cc_get_thumbnail( 78, 78 ); ?>                    
                                            <?php } else { ?>
                                                <?php cc_get_image( 78, 78, \'\', $postimg ); ?> 
                                                <?php
                                            }
                                            $taxonomies = get_the_term_list( $post->ID, CUSTOM_CAT_TYPE, \'\', \',\', \'\' );
                                            ?>
                                            <section class="thumb_item">
                                                <?php if ( get_post_meta( $post->ID, \'cc_price\', true ) !== \'\' ) { ?>
                                                    <span class="price"><?php
                                                        if ( cc_get_option( \'cc_currency\' ) != \'\' ) {
                                                            echo cc_get_option( \'cc_currency\' );
                                                        } else {
                                                            echo get_option( \'currency_symbol\' );
                                                        }
                                                        echo get_post_meta( $post->ID, \'cc_price\', true );
                                                        ?></span>
                                                <?php } ?>
                                                <a class="view" href="<?php the_permalink(); ?>"><?php echo VIEW_IT; ?></a>
                                            </section>
                                        </section>
                                        <section class="contents">
                                            <h6 class="title"><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h6>
                                            <?php the_excerpt(); ?>
                                            <div class="clear"></div>
                                            <ul class="post_meta">
                                                <li class="estimate"><?php echo human_time_diff( get_the_time( \'U\' ), current_time( \'timestamp\' ) ) . \' \' . AGO; ?></li>
                                                <li class="cate"><?php echo $taxonomies; ?></li>
                                                <li class="author"><?php echo BY; ?>&nbsp;<?php the_author_posts_link(); ?></li>
                                            </ul>

                                        </section>
                                    </li>
                                    <!-- row 1 -->   
                                    <?php
                                endwhile;
                                ?>                                       
                            </ul> 
                            <?php
                        endif;
                        wp_reset_query();
                        cc_pagination();
                        ?>
                        <div class="clear"></div>
                    </div>
                    <!--End Cotent-->
                </div>
                <div class="grid_7 omega">
                    <?php get_sidebar(); ?>
                </div>
            </div>
            <div class="clear"></div>
        </div>
    </div>
    <!--End Cotent Wrapper-->
    <?php
    get_footer();
}
?>

1 个回复
SO网友:worldwildwebdev

您可以在functions.php 就像这样:

function get_user_role($id) {

    $user = new WP_User($id);

    return array_shift($user->roles);

}
然后在模板文件中调用函数:

<?php $aid = get_the_author_meta(\'ID\'); 
echo get_user_role($aid); ?>

结束

相关推荐

Query Set Order By Author

当您单击票证列表上的“作者”箭头时,我试图按author\\u名称排序。单击箭头时,名称按我无法识别的顺序排列。我希望他们按实际名称而不是用户的ID号订购。如何让orderby按照用户(作者)的“好名字”进行查询?public function add_support_ticket_author_query( $query ) { if ( $query->is_main_query() && ( $orderby = $query->get( \'or