• 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

Viewing 11 replies - 1 through 11 (of 11 total)
  • 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>';
      }
    }
    ?>
    Thread Starter plinth

    (@plinth)

    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?

    This around the echo:

    if ($post_count) {
     echo '<li><a href="' . $author_posts_url . '">' . $user->user_firstname . ' ' . $user->user_lastname . '</a> (' . $post_count . ') </li>';
    
    }

    Thread Starter plinth

    (@plinth)

    Brilliant!

    Now here’s a challenge for you – how about making the most recent poster rise to the top of the list…

    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>
    Thread Starter plinth

    (@plinth)

    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…

    adedip

    (@adedip)

    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

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

    thank you!

    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>

    @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>

    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!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Possible to list authors by their last post date?’ is closed to new replies.