• Resolved Ferdynando

    (@ferdynando)


    Hello.
    I know that were already similar topics (I read them all), but none of them didn’t help me:( So – I would like to display list of all authors from my website (only links to author’s profiles), and add pagination to this list. For example – you enter the page named “Authors”, and there are 50 links to my author’s profiles, and on next page are next 50 links and so on. It would be best, if that authors would be ordered by count of they articles, and users with no posts wouldn’t be displayed. Now I use function named “wp_list_authors”, but – from what I learned – this cant add pagination to the list.
    I tried “wp_user_query” function too, but unfortunatelly all of the code which I found didn,t work on my site (it display empty page or error). I dont know if it is fault of my theme, or maybe reason is that codes which I tried was unnactually. As I mentioned, I was looking for a solution on this forum and on another sites too. I read the “function reference” in WordPress Codex, but I can not very well php, and also I can not very well English (which is probably easy to see in this post). However, I hope that someone help me and show me working code to display list of site authors with pagination. I have installed the “Page-Navi” plugin.
    Regards and thanks in advance for your help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The code below should be close to what you want:

    $authors_per_page = 50;
    
    $args = array(
       'orderby' => 'post_count',
       'order' => 'desc',
       'optioncount' => true,
       'html' => 1,
       'echo' => 0,
    );
    $author_string = wp_list_authors($args);
    $authors = explode('<li>', $author_string);
    // Because there is a leading <li>, the first array entry is empty
    array_shift($authors);
    
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') :
          (( get_query_var('page') ) ? get_query_var('page') : 1);
    
    global $wp_rewrite;
    
    $pagination_args = array(
     'base' => @add_query_arg('paged','%#%'),
     'format' => '',
     'total' => ceil(sizeof($authors)/$authors_per_page),
     'current' => $paged,
     'show_all' => false,
     'type' => 'plain',
    );
    
    if( $wp_rewrite->using_permalinks() )
     $pagination_args['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'paged');
    
    if( !empty($wp_query->query_vars['s']) )
     $pagination_args['add_args'] = array('s'=>get_query_var('s'));
    
    $links = paginate_links($pagination_args);
    echo $links;
    
    $start = ($paged - 1) * $authors_per_page;
    $end = $start + $authors_per_page;
    $end = (sizeof($authors) < $end) ? sizeof($authors) : $end;
    
    echo '<br />';
    for ($i=$start;$i < $end ;++$i ) {
     $row = $authors[$i];
     echo "<li>$row";
    }
    echo '<br />';
    echo $links;
    Thread Starter Ferdynando

    (@ferdynando)

    Thank you very, very much! It works great. Finally i got it, what I was looking for so long. Thanks!

    I need something very similar. I’m currently using this code to display the list with nothing but subscribers (and their emails) excluding the admin account:

    <ul>
    			<?php
    
    			    $args  = array(
    			        'who' => 'subscribers',
    			        'orderby' => 'user_registered',
    					'order' => 'DEC',
    					'exclude' => '1'
    			    );
    
    			    $wp_user_query = new WP_User_Query($args);
    
    			    if ( ! empty( $wp_user_query->results ) ) {
    			        foreach ( $wp_user_query->results as $user ) {
    
    			            echo '<li class="abc"><a href="' . get_author_posts_url( $user->ID ) . '">' . $user->display_name . '</a> - <a href="' . get_author_posts_url( $user->ID ) . '">' . $user->user_email . '</a></li>';
    
    			        }
    			    }
    
    			?>
    		</ul>

    I would love to have pagination for this. Any help would be appreciated.

    Thanks

    Normally you would not get any results by replying to a ‘Resolved’ post. Better to start your own thread.

    However, try this:

    <?php
    
    $posts_per_page = 20;
    
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') :
          (( get_query_var('page') ) ? get_query_var('page') : 1);
    
    $args  = array(
       'who' => 'subscribers',
       'orderby' => 'user_registered',
       'order' => 'DESC',
       'exclude' => array( 1 ),
       'number' => $posts_per_page,
       'offset' => (($paged - 1) * $posts_per_page),
    );
    
    $wp_user_query = new WP_User_Query($args);
    
    if ( ! empty( $wp_user_query->results ) ) { ?>
    
       <ul>
    
       <?php foreach ( $wp_user_query->results as $user ) {
    
          echo '<li class="abc"><a href="' . get_author_posts_url( $user->ID ) . '">' . $user->display_name . '</a> - <a href="' . get_author_posts_url( $user->ID ) . '">' . $user->user_email . '</a></li>';
    
       } ?>
    
       </ul>
    
       <?php global $wp_rewrite;
    
       $pagination_args = array(
          'base' => @add_query_arg('paged','%#%'),
          'format' => '',
          'total' => ceil($wp_user_query->get_total() / $posts_per_page),
          'current' => $paged,
          'show_all' => false,
          'type' => 'plain',
       );
    
       if( $wp_rewrite->using_permalinks() )
          $pagination_args['base'] = user_trailingslashit( trailingslashit( remove_query_arg('s',get_pagenum_link(1) ) ) . 'page/%#%/', 'paged');
    
       if( !empty($wp_query->query_vars['s']) )
          $pagination_args['add_args'] = array('s'=>get_query_var('s'));
    
       $links = paginate_links($pagination_args);
       echo "<div class='navigation'>$links</div>";
    }
    
    ?>

    Thank you vtxyzzy. It worked perfectly.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘List of all authors with pagination’ is closed to new replies.