WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a contributors page on my blog that I have recently started and using some code online this is working pretty well.


I would love it to do two extra things:

1) Only list members who have at least one approved post on the site 2) List the members previous 5 posts

Here is the code I am using currently,

<?php /*
Template Name: Authors
*/ ?>

<?php get_header(); ?>

<div id="content" class="clearfix">
<div id="main" class="col620 clearfix" role="main">

<?php if(have_posts()) : while(have_posts()) : the_post(); ?>

<article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<header class="entry-header">
<h1 class="entry-title"><?php the_title(); ?></h1>
</header><!-- .entry-header -->

<div class="entry-content post_content">
<?php the_content(); ?>

<?php endwhile; endif; ?>


// Get the authors from the database ordered by user nicename
global $wpdb;
$query = "SELECT ID, user_nicename from $wpdb->users ORDER BY user_nicename";
$author_ids = $wpdb->get_results($query);

// Loop through each author
foreach($author_ids as $author) :

// Get user data
$curauth = get_userdata($author->ID);

// If user level is above 0 or login name is "admin", display profile
if($curauth->user_level > 0 || $curauth->user_login == 'admin') :

// Get link to author page
$user_link = get_author_posts_url($curauth->ID);

// Set default avatar (values = default, wavatar, identicon, monsterid)
$avatar = 'wavatar';

<div id="container" style="padding:10px 10px;">
<div class="author single_postmeta">

<a href="<?php echo $user_link; ?>" title="<?php echo $curauth->display_name; ?>">
<?php echo get_avatar($curauth->user_email, '96', $avatar); ?>

<h3 class="post-title">
<a href="<?php echo $user_link; ?>" title="<?php echo $curauth->display_name; ?>"><?php         echo $curauth->display_name; ?></a><br>

<?php if(get_the_author_meta('jobtitle', $curauth->ID)): ?>
<?php the_author_meta('jobtitle', $curauth->ID); ?> at <?php the_author_meta('company', $curauth->ID); ?>
<?php endif; ?>

<p><?php echo $curauth->description; ?> </p>

<?php if(get_the_author_meta('twitter', $curauth->ID)): ?>
<li><a href='http://twitter.com/<?php the_author_meta('twitter', $curauth->ID); ?>'>Follow <?php the_author_meta('first_name', $curauth->ID); ?> on twitter  &rarr;</a></li>
<?php endif; ?>
<?php if(get_the_author_meta('facebook', $curauth->ID)): ?>
<li><a href='<?php the_author_meta('facebook', $curauth->ID); ?>'>Find <?php the_author_meta('first_name', $curauth->ID); ?> on Facebook  &rarr;</a></li>
<?php endif; ?>
<?php if(get_the_author_meta('linkedin', $curauth->ID)): ?>
<li><a href='<?php the_author_meta('linkedin', $curauth->ID); ?>'>Connect with <?php the_author_meta('first_name', $curauth->ID); ?> on Linkedin  &rarr;</a></li>
<?php endif; ?>
<?php if(get_the_author_meta('googleplus', $curauth->ID)): ?>
<li><a href='<?php the_author_meta('googleplus', $curauth->ID); ?>'>Add <?php the_author_meta('first_name', $curauth->ID); ?> to your circle on Google+ &rarr;</a></li>
<?php endif; ?>



<?php endif; ?>
<?php endforeach; ?>

<?php get_footer(); ?>

Would appreciate any help you can give,

Thanks James

share|improve this question
// retrieve latest 5(or all) posts of this user
$query = new WP_Query(array(
    'author' => $author,
    'posts_per_page' => 5

// skip the user if the number of posts is 0
if($query->post_count < 1)

// loop through available posts & display the title
while($query->have_posts()) :

This code should go inside the your foreach loop

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.