0 votes
in Website Design by (1.9k points)

php template please tell me how to show author role

<?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>

Here is my sample code 

please help me to solve this problem?

Thanks!!

1 Answer

0 votes
by (2.4k points)

You can register a function in your functions.php like that:

function get_user_role($id) {

    $user = new WP_User($id);

    return array_shift($user->roles);

}

Then in template file you call the function:

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

 

Hope so its according to your requirment!

131 questions

117 answers

7 comments

378 users

Welcome to Todayask Q&A, where you can ask questions and receive answers from other members of the community.
...