0

Basically I am struggling to display the author list in a grid:

<div class="container">
<div class="row">
<div class="col-lg-4">
<?php 

wp_list_authors( array(
    'show_fullname' => 1,
    'optioncount'   => 1,
    'exclude' => 4,
    'orderby'       => 'post_count',
    'order'         => 'DESC',
    'number'        => 60
) ); ?>
</div>
</div>
</div>

Should I use the user table instead of is there a loop I can use against the author list?

Thank you

1
  • You're on the right track with using a loop. The problem you are running into is wp_list_authors returns a list either comma separated or as <li> but you want to pass the data into a grid. Can you update your question with what the HTML markup that each author should be wrapped in for those of us who don't use Bootstrap?
    – Brooke.
    May 8, 2020 at 15:22

2 Answers 2

-1

Not many ways to style the wp_list_author but you can use the style => 'list' argument to display authors in <li> and then style your <ul>as wanted. https://developer.wordpress.org/reference/functions/wp_list_authors/

    <div class="container">
<div class="row">
<div class="col-lg-4">
    <ul class="d-flex">
<?php 

wp_list_authors( array(
    'exclude' => 4,
    'show_fullname' => 1,
    'optioncount'   => 1,
    'orderby'       => 'post_count',
    'order'         => 'DESC',
    'number'        => 60,
    'style'         => 'list',
) ); ?>

    </ul>
</div>
</div>
</div>  

For example adding the d-flexclass to your <ul>

You could also use the get_usersfunction.

https://developer.wordpress.org/reference/functions/get_users/

I update my code below with this query you can have the bootstrap grid ;)

<?php 
$users    = get_users('');
$query    = get_users( [ 'role__in' => [ 'author', 'editor' ],
                        'number'=> 60,
    'exclude' => 4,
    'orderby'       => 'post_count',
    'order'         => 'DESC', ]);

?>
 <div class="container">
<div class="row">
    <?php
foreach($query as $q) { ?>


<div class="col-lg-4">
          <?php echo get_the_author_meta('display_name', $q->ID);?>
</div>

<?php } ?>
</div>
</div>
8
  • Thanks thats certainly an interesting way, is it possible to loop it instead to a bootstrap column? The wordpress documentation on this function isn't very clear
    – kamboodle
    May 8, 2020 at 14:22
  • After further search, I updated my answer with a solution wich will allow you to loop the authors. If ok thanx to mark as solved
    – gael
    May 8, 2020 at 15:16
  • thank looks perfect but i am getting the wordpress white page of death when i add it to my custom author page: <?php $users = get_users(''); $query = get_users( [ 'role__in' => [ 'author', 'editor' ], 'number'=> 60, 'optioncount' => 1, 'exclude' => 4, 'orderby' => 'post_count', 'order' => 'DESC', ]); ?> <div class="container"> <div class="row"> <?php foreach($query as $q) { ?> <div class="col-lg-4"> <?php echo get_the_author_meta('display_name', $q->ID);?> </div> <?php } ?> </div> </div>
    – kamboodle
    May 8, 2020 at 15:55
  • You should activate debug mode to get the corresponding error message.
    – gael
    May 8, 2020 at 15:59
  • [08-May-2020 11:53:34 UTC] PHP Warning: Invalid argument supplied for foreach() in /home/ I feel so out of my depth here and really appreciate any help
    – kamboodle
    May 8, 2020 at 16:02
-1

It looks like this can be achieved easily using Visual Composer plugin.

Take a look at this link with brief instructions.

https://wpexplorer-themes.com/total/docs/display-users/

Here's a link to the plugin: https://wordpress.org/plugins/visualcomposer/

2
  • Thanks but I am not using that theme, I am coding my own and wish to do it without plugins
    – kamboodle
    May 8, 2020 at 13:03
  • Can I see a link to the current page?
    – Androliyah
    May 8, 2020 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.