WordPress.org

Forums

list users - inside a POST!! (5 posts)

  1. mores
    Member
    Posted 6 years ago #

    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 ?

  2. MichaelH
    Member
    Posted 6 years ago #

    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.

  3. mores
    Member
    Posted 6 years ago #

    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 :)

  4. mores
    Member
    Posted 6 years ago #

    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.)

  5. t31os
    Member
    Posted 6 years ago #

    You might find some info here of use..

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

Topic Closed

This topic has been closed to new replies.

About this Topic