Reputation: 16196
I want to display users of wordpress as a table just like https://stackoverflow.com/users
The recommended function is wp_list_authors, but it is not clear how can customise the layout.
Say I want to display users in cells of table 5 x 5 with get next page link.
Please advice.
Let me explain a bit.
Unlike get_users_of_blog wp_list_authors does not return an array. If it would - then
having an array I can build any table using foreach
. But wp_list_authors builds anchor tags on its own and returns monolith html block. The only option to control layout would be passing some sort before and after tags. But this function does not provide this sort of functionality.
Upvotes: 0
Views: 551
Reputation: 1559
As far as i know, there's no function like get_authors()
, but you can do it by a raw SQL query in a custom template:
Update: For pagination
I'm not sure if you can use the built-in WordPress pagination to do that, as the paged
param only appear to posts. You could fill a global $post var in a loop or something... There's a lot of approaches, but let's go for the "PHP" one. =D
<?php
$i = 0;
$limit = 25;
$offset = ($o = trim($_GET['offset'])) ? $o : 0;
$users = $wpdb->get_results("SELECT user_nicename ... FROM {$wpdb->users} LIMIT $offset,$limit");
?>
<?php foreach ($users as $user) : ?>
<div class="someclass">
<?php echo $user->user_nicename; ?>
</div>
<?php if ($i++ % $number_of_columns == 0) : ?>
<div class="padder"></div>
<?php endif; ?>
<?php endforeach; ?>
To simulate the table appearance, just float "someclass" left and put a fixed width on it. The "padder" div (float left and width 100%) will ensure that the cells will be aligned by the highest one in that row.
And for the pagination links:
<?php $n = $wpdb->get_var("SELECT count(ID) FROM {$wpdb->users}"); ?>
<?php $o = $offset - $limit; ?>
<?php if ($offset > 0) : ?>
<a class="prev" href="?offset=<?php echo $offset - $limit; ?>">Previous</a>
<?php endif; ?>
<?php $o = $offset + $limit; ?>
<?php if ($o < $n) : ?>
<a class="next" href="?offset=<?php echo $o; ?>">Next</a>
<?php endif; ?>
Code from brain to keyboard. Not tested, again.
Hope it helps.
Upvotes: 1