• I’m looking for a plugin or method of displaying a random number of registered user urls in the sidebar. Can someone point me in the right direction?

Viewing 1 replies (of 1 total)
  • To make sure I got your request right, you want the number of user urls displayed to be random, or rather the selection of those urls?

    Don’t know of a plugin, but displaying random (but a fixed number of) user urls is a somewhat simple bit of code:

    <ul>
    <?php
    global $wpdb;

    $limit_urls = 10; // set to # of urls to display

    $randusers = $wpdb->get_results("SELECT * FROM $wpdb->users ORDER BY RAND() LIMIT $limit_urls");

    foreach($randusers as $user) :
    $linkname = ($user->display_name) ? $user->display_name : $user->user_login;
    ?>
    <li><a href="<?php echo $user->user_url; ?>"><?php echo $linkname; ?></a></li>
    <?php endforeach; ?>
    </ul>

    Change the $limit_urls value to set the number of links to display. Note that $linkname tests whether a display name has been set (if not, login name is used).

    For a random number of urls, change the $limit_urls line to:

    $limit_urls = mt_rand(0, $wpdb->get_var("SELECT COUNT(ID) FROM $wpdb->users"));

    This generates a random number with the max (highest number) argument seeded by a count of the user IDs.

Viewing 1 replies (of 1 total)
  • The topic ‘Random Registerd User Links’ is closed to new replies.