WordPress.org

Ready to get started?Download WordPress

Forums

Possible to list authors by their last post date? (12 posts)

  1. plinth
    Member
    Posted 4 years ago #

    Hi, some of the contributing authors on my blog are frequently active and some are not. I'd like to list them on the authors page and on a drop-down list in descending order of the most active poster.

    Is this possible?

    Thanks

  2. MichaelH
    Member
    Posted 4 years ago #

    From my notes, this:

    <?php
    //List of users sorted Descending by number of posts
    $uc=array();
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $post_count = get_usernumposts($bloguser->user_id);
        $uc[$bloguser->user_id]=$post_count;
      }
      arsort($uc);
      foreach ($uc as $key => $value) {
        $user = get_userdata($key);
        $author_posts_url = get_author_posts_url($key);
        $post_count = $value;
        echo '<p>User ID ' . $user->ID . ' First: ' . $user->user_firstname . ' Last: ' . $user->user_lastname . ' number of posts: ' . $post_count . '  author posts url: ' . $author_posts_url .'<p>';
      }
    }
    ?>
  3. plinth
    Member
    Posted 4 years ago #

    Thanks MichaelH, with a little tweaking of your code I've put this together:

    <ul>
    <?php
    //List of users sorted Descending by number of posts
    $uc=array();
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $post_count = get_usernumposts($bloguser->user_id);
        $uc[$bloguser->user_id]=$post_count;
      }
      arsort($uc);
      foreach ($uc as $key => $value) {
        $user = get_userdata($key);
        $author_posts_url = get_author_posts_url($key);
        $post_count = $value;
        echo '<li><a href="' . $author_posts_url . '">' . $user->user_firstname . ' ' . $user->user_lastname . '</a> (' . $post_count . ') </li>';
      }
    }
    ?>
    </ul>

    However, I'd like to exclude authors with 0 posts - is this do-able?

  4. MichaelH
    Member
    Posted 4 years ago #

    This around the echo:

    if ($post_count) {
     echo '<li><a href="' . $author_posts_url . '">' . $user->user_firstname . ' ' . $user->user_lastname . '</a> (' . $post_count . ') </li>';
    
    }
  5. plinth
    Member
    Posted 4 years ago #

    Brilliant!

    Now here's a challenge for you - how about making the most recent poster rise to the top of the list...

  6. MichaelH
    Member
    Posted 4 years ago #

    Hmm might try this:

    <ul>
    <?php
    //List of users sorted descending by date of lastest post written by user
    $uc=array();
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $userpost = get_posts('showposts=1&author='.$bloguser->user_id);
        $uc[$bloguser->user_id] = '';
        if ($userpost) {
          $uc[$bloguser->user_id]=$userpost[0]->post_date;
        }
      }
      arsort($uc);
      foreach ($uc as $key => $value) {
        $user = get_userdata($key);
        $post_count = get_usernumposts($user->ID);
        if ($post_count) {
          $author_posts_url = get_author_posts_url($key);
          echo '<li><a href="' . $author_posts_url . '">' . $user->user_firstname . ' ' . $user->user_lastname . '</a> (' . $post_count . ') </li>';
        }
      }
    }
    ?>
    </ul>
  7. plinth
    Member
    Posted 4 years ago #

    That's fantastic, thanks.

    Not to be outdone, the client has now suggest those who have not posted in the last 3 months be missed off the list...

  8. adedip
    Member
    Posted 4 years ago #

    Nice work..very useful.. I'd need two more things..the first quite easy is to exclude certain ids (like admin one ad others few)

    the second is more complex..because it changes the philosophy of this..I'd need to list for each months its authors. I can I add this?

    I have 7 authors in each month and they just wrote in that particular month(year)..I can I list them?

    thx

  9. Nikolas
    Member
    Posted 4 years ago #

    hello there! please let me know how can i limit the echoed users to 5.

    thank you!

  10. Nikolas
    Member
    Posted 4 years ago #

    anyone ? the code is the above...

    <ul>
    <?php
    //List of users sorted descending by date of lastest post written by user
    $uc=array();
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $userpost = get_posts('showposts=1&author='.$bloguser->user_id);
        $uc[$bloguser->user_id] = '';
        if ($userpost) {
          $uc[$bloguser->user_id]=$userpost[0]->post_date;
        }
      }
      arsort($uc);
      foreach ($uc as $key => $value) {
        $user = get_userdata($key);
        $post_count = get_usernumposts($user->ID);
        if ($post_count) {
          $author_posts_url = get_author_posts_url($key);
          echo '<li><a href="' . $author_posts_url . '">' . $user->user_firstname . ' ' . $user->user_lastname . '</a> (' . $post_count . ') </li>';
        }
      }
    }
    ?>
    </ul>
  11. tugbucket
    Member
    Posted 4 years ago #

    @kordellas

    <ul>
    <?php
    //List of users sorted descending by date of lastest post written by user
    $uc=array();
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $userpost = get_posts('showposts=1&author='.$bloguser->user_id);
        $uc[$bloguser->user_id] = '';
        if ($userpost) {
          $uc[$bloguser->user_id]=$userpost[0]->post_date;
        }
      }
      arsort($uc);
      $i = 0;
      foreach ($uc as $key => $value) {
        $user = get_userdata($key);
        $post_count = get_usernumposts($user->ID);
        if ($post_count && $i < 5) {
          $author_posts_url = get_author_posts_url($key);
          echo '<li><a href="' . $author_posts_url . '">' . $user->user_firstname . ' ' . $user->user_lastname . '</a> (' . $post_count . ') </li>';
        }
      $i++;
      }
    }
    ?>
    </ul>
  12. Nikolas
    Member
    Posted 4 years ago #

    Thank you friend!
    I appreciate this. I think this piece of code is useful to many bloggers.

    So, is there any way to get the avatar of the author too?

    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic