Support » Fixing WordPress » list users – inside a POST!!

  • Hi all,

    I’m fairly confident that I’d be able to get a list of registered users to display in a Page or sidebar.
    But since I developed a site that’s completely based on posts and categories, and there is a Post called “users” that needs to show a list of all users.

    So … how to do ?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Use a php exec type plugin and use the template tag, wp_list_authors() in the post.

    Or use this plugin http://wordpress.org/extend/plugins/template-tag-shortcodes/ and use the wp_list_authors shortcode in your post.

    Thank you, Michael, for the quick reply.

    What seems easier at first, the template-tag-shortcodes plugin, turns out to be not useful for me, since I need to do some serious formatting with the user list, which I’d need to to with php.

    So … let’s look at exec-php 🙂

    Hmm, I decided to create a plugin, but while fiddling around, I realized I can do it all from inside a functions.php.
    Here’s my code, in case anyone wants to do something similar:

    add_filter('the_content', 'display_users_replace_marker');
    
    function display_users() {
    	global $wpdb;
    	$authors = $wpdb->get_results("SELECT ID, display_name from $wpdb->users where id != 1 ORDER BY display_name ASC");
    	$allusers = '';
    
    	$i=1;
    	foreach ($authors as $author) {
    		$allusers .= '<div class="usercolumn'.$i.'"><h2>'.$author->display_name.'</h2></div>';
    		$i++; if ($i==4) {$i=1;}
    	}
    
    	return $allusers;
    }
    
    function display_users_replace_marker($content) {
    	if(!preg_match('[display_users]', $content)) {
    			return $content;
    		}
    		else {
    			$allusers = display_users();
    			return str_replace('[display_users]', $allusers, $content);
    		}
    }

    I’d appreciate any input as to how clean this thing is. I’m not looking for long-term stability since I will not be updating this user’s website to newer WP versions. So if it works now, I’ll keep it 🙂
    (it’s a site that’s only interesting for a limited time and will be turned off after the event.)

    You might find some info here of use..

    http://www.mattvarone.com/wordpress/list-users/

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘list users – inside a POST!!’ is closed to new replies.