As communities grow, so does the need to showcase your authors. Having a hefty community of authors is a great thing (content producers FTW!) but everyone wants their fifteen minutes. This handy little tip can help make sure everyone gets their fair share of the limelight.
A couple of things to note first: Make sure that you’ve got author archives set up. You can hack this to work with author profiles, but that’s not the scope of this tutorial. Also, this tutorial assumes that your server is parsing whatever page this is on as PHP. As a rule of thumb, if your file extension is .html, this probably won’t work; if you’re file extension is .php, you should be fine.
<?php
$displayed_authors = array(); // Will hold indexes from $authors for authors already displayed
$show = 25; // How many authors should we show?
<mt:Authors>
$authors[<mt:AuthorId />] = '<li><a href="<mt:EntryLink archive_type="Author" />"><mt:EntryAuthorDisplayName encode_php='1' /></a></li>';
</mt:Authors>
for ($i=1; $i <= $show; $i++) {
$rn = array_rand($authors);
// Loops until it finds an author not displayed
while(in_array($rn, $displayed_authors)) {
$rn = array_rand($authors);
}
array_push($displayed_authors, $rn);
echo $authors[$rn];
}
?>
First, we set up an array where we’ll store all the authors that have already been displayed. More on that in a minute. Then we define how many authors we want to show with this block.
