WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] sort authors (4 posts)

  1. mlarris
    Member
    Posted 4 years ago #

    I use the Hybrid theme which has an authors page. I would like to display the authors of the blog in descending order by ID. Or maybe by latest entry on the blog.

    Can anybody help me?

    <?php foreach ( get_users_of_blog() as $author ) : ?>
    
    						<?php if ( get_the_author_meta( 'user_level', $author->ID ) > 0 || get_the_author_meta( 'user_login', $author->ID ) == 'admin' ) : ?>
    
    							<div id="hcard-<?php echo str_replace( ' ', '-', get_the_author_meta( 'user_nicename', $author->ID ) ); ?>" class="author-profile vcard clear">
    
    								<a href="<?php echo get_author_posts_url( $author->ID ); ?>" title="<?php the_author_meta( 'display_name', $author->ID ); ?>">
    
                                        <?php  the_author_image($author->ID);'width="130" height="160"';?>
    
    								</a>
    								<h2 class="author-name fn n">
    									<a href="<?php echo get_author_posts_url( $author->ID ); ?>" title="<?php the_author_meta( 'display_name', $author->ID ); ?>"><?php the_author_meta( 'display_name', $author->ID ); ?></a>
    								</h2>
    								<p class="author-bio">
    									<?php the_author_meta( 'description', $author->ID ); ?>
    								</p><!-- .author-bio -->
    
    							</div><!-- .author-profile .vcard -->
    
    						<?php endif; ?>
    
    					<?php endforeach; ?>
  2. MichaelH
    Member
    Posted 4 years ago #

    Here's one example:

    <ul>
    <?php
    //List of users sorted descending by date of lastest post written by user
    $uc=array();
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $userpost = get_posts('showposts=1&author='.$bloguser->user_id);
        $uc[$bloguser->user_id] = '';
        if ($userpost) {
          $uc[$bloguser->user_id]=$userpost[0]->post_date;
        }
      }
      arsort($uc);
      foreach ($uc as $key => $value) {
        $user = get_userdata($key);
        $post_count = get_usernumposts($user->ID);
        if ($post_count) {
          $author_posts_url = get_author_posts_url($key);
          echo '<li><a href="' . $author_posts_url . '">' . $user->user_firstname . ' ' . $user->user_lastname . '</a> (' . $post_count . ') </li>';
        }
      }
    }
    ?>
    </ul>
  3. mlarris
    Member
    Posted 4 years ago #

    OK, that works, but not in the right way.
    The authorspage in the Hybrid theme puts authorinformation + gravatar, or as I did the authorimage from the authorimage plugin. So I would like to use the above code but with an output in descending order, to have this nice overview of authors in the blog.
    Hope You can help me?

  4. mlarris
    Member
    Posted 4 years ago #

    Well I figured out myself to change in the user.php file. Line 281 I added DESC.
    'ORDER BY {$wpdb->usermeta}.user_id DESC"'

Topic Closed

This topic has been closed to new replies.

About this Topic