Forums

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

  1. plinth
    Member
    Posted 1 month 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
    moderator
    Posted 1 month 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 1 month 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
    moderator
    Posted 1 month 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 1 month 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
    moderator
    Posted 1 month 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 1 month 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 3 weeks 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

Reply

You must log in to post.

About this Topic