Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a Author page that I built using this code and it works fine. However, I have several writers that range from frequent to one-time writers. I would like to seperate out writers that have not posted an article for say 6 months. It would be nice then to output those writers in a different section like "Past Writers" or something after the other list of writers.

NOTE: I know little to nothing about coding so specific code help is needed!

Here is the code I am using now

<?php
// Arguments to pass to get_users
// ************* $args = array( 'orderby' => 'post_count', 'order' => 'DSC', 'who' => 'authors' );
// Query for the users
$authors = get_users('orderby=post_count&order=DSC&role=contributor'); ?>
<h4 style="padding-top:20px;">Writers</h4>
<?php
// Loop through all the users, printing all of their posts as we go
foreach ( $authors as $author ) { ?>
            <a name="<?php echo $author->user_nicename; ?>"></a>
            <div class="author-posts-wrapper" id="author-<?php echo $author->ID; ?>-posts-wrapper">
                <div class="author-avatar" id="author-<?php echo $author->ID; ?>-avatar">
                    <?php echo get_avatar( $author->ID, 96 ); ?>
                </div>
                <div class="author-posts" id="author-<?php echo $author->ID; ?>-posts">
                    <h2><a href="<?php echo get_author_posts_url( $author->ID ); ?>"><?php echo $author->display_name; ?></a></h2>
    <?php
    // Set up a Loop, querying for all of the current user's posts
    $args = array( 'author' => $author->ID, 'posts_per_page' => 1 );
    $posts = query_posts($args);
    // Now that we have the posts, simulate a Loop here
    if ( have_posts() ) : ?>
                <ul class="author-post-list" id="author-<?php echo $author->ID; ?>-post-list">
        <?php while ( have_posts() ) : the_post(); // Print whatever we want for each post - for now the title ?>
                    <div class="author-descrip" style="padding-bottom:2px;"><?php the_author_meta("description"); ?></div>
          <p style="font-size:14px; color:#555;"><strong><?php the_author_posts(); ?> articles written. Most recent: <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></strong></p>
          <p style="padding-top:8px;">
            <?php if(get_the_author_meta('user_url')): ?>
          </p>
        <?php endwhile; ?>
                </ul><!-- #author-post-list -->
    <?php else: ?>
                    <p style="font-style:italic;">This author has not yet published any posts</p>
    <?php endif; ?>
                </div><!-- #author-posts -->
            </div><!-- #author-posts-wrapper -->
      <br />
<?php } // End looping over all users ?>
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Wordpress itself does not store this info directly in database... yet you have some elegant options:

you can hook into "publish post" and update list of "active users" when someone posts his/her published, you can store this information then in options table in serialized array. In this array you can have list of authors and when they published their last post, which you use for picking recent active...

OR

You can just edit this one php template, you have to loop through all authors and separate them accordingly in foreach loop before you print output... for speeding up page you can store filtered users or whole content of page in wordpress transient, where you can easily cashe arrays or plan html output, see wordpress transient api: http://codex.wordpress.org/Transients_API

OR

You can simply skip autor whose last post is older than 6 months like this:

<?php
// Arguments to pass to get_users
// ************* $args = array( 'orderby' => 'post_count', 'order' => 'DSC', 'who' => 'authors' );
// Query for the users
$authors = get_users('orderby=post_count&order=DSC'); //&role=contributor ?>
<h4 style="padding-top:20px;">Writers</h4>  
<?php
// Loop through all the users, printing all of their posts as we go
foreach ( $authors as $author ) {

    // Set up a Loop, querying for all of the current user's posts
    $args = array( 'author' => $author->ID, 'posts_per_page' => 1 );
    $posts = query_posts($args);

    if (6 < (date('n',(time() - strtotime($posts[0]->post_date)))))
        continue; //skips this autor as long as his last post is older than 6 months, be aware that this check uses date function.

 ?>
            <a name="<?php echo $author->user_nicename; ?>"></a>
            <div class="author-posts-wrapper" id="author-<?php echo $author->ID; ?>-posts-wrapper">
                <div class="author-avatar" id="author-<?php echo $author->ID; ?>-avatar">
                    <?php echo get_avatar( $author->ID, 96 ); ?>
                </div>
                <div class="author-posts" id="author-<?php echo $author->ID; ?>-posts">
                    <h2><a href="<?php echo get_author_posts_url( $author->ID ); ?>"><?php echo $author->display_name; ?></a></h2>

    <?php if ( have_posts() ) :  ?>
                <ul class="author-post-list" id="author-<?php echo $author->ID; ?>-post-list">
        <?php while ( have_posts() ) : the_post(); // Print whatever we want for each post - for now the title ?>
                    <div class="author-descrip" style="padding-bottom:2px;">
                        <?php the_author_meta("description"); ?></div>
          <p style="font-size:14px; color:#555;"><strong><?php the_author_posts(); ?> articles written. Most recent: <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></strong></p>
          <p style="padding-top:8px;">
            <?php if(get_the_author_meta('user_url')): ?>
                <?= get_the_author_meta('user_url') ?>
            <?php endif; ?>
          </p>
        <?php endwhile; ?>
                </ul><!-- #author-post-list -->
    <?php else: ?>
                    <p style="font-style:italic;">This author has not yet published any posts</p>
    <?php endif; ?>
                </div><!-- #author-posts -->
            </div><!-- #author-posts-wrapper -->
      <br />
<?php } // End looping over all users ?>
share|improve this answer
    
Could you give me an example of what that foreach loop would look like? I don't know much about coding so not sure precisely what you mean without specific code. Thanks! –  Dustin J Nov 6 '12 at 20:11
    
here you are :-) –  Roman Nov 13 '12 at 1:36
    
that works perfectly, however, is there any way to then output those authors we skipped over and display them in a list? Or is that part what makes it so difficult to do? –  Dustin J Nov 13 '12 at 15:15
    
actually it is simple, you can store those authors to aditional array and print them later in code... just edit this part: if (6 < (date('n',(time() - strtotime($posts[0]->post_date))))) { $old_authors[] = $author ; continue;} then you have all old authors in another array which you can go thru again in with another foreach loop, and not looping for his/her posts, just displaying name and so no... –  Roman Nov 14 '12 at 20:18
1  
@VincePettit That code seemed to have worked perfectly! Thanks so much. –  Dustin J Apr 17 '13 at 16:23

Your Answer

 
discard

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.