Support » Themes and Templates » List posts only from authors level?

  • Hi there, please guys, I need to finalize an job, list the last 2 posts from authors, only from authors level.

    This list it will display the author avatar, the autor name, the post title and the date of the post title.

    The HTML structure is below:

     <img src="AVATAR"/>
     <h6>[author name] at [post date]</h6>
     <a href="#" title="rrrr">[post title]</a>

    Help-me guys!

Viewing 8 replies - 1 through 8 (of 8 total)
  • So you are saying, display a list of users that are of the Author role and display two posts for each of those Authors–correct?

    What if they are of the Author role and don’t have any posts?

    Hi MichaelH, no, I need list the last 2 posts from authors role, ordered by date in my homepage. But I need only authors role. Excluding from this list, posts by Admins and others roles.

    //displays users of author role and two posts for each
    $blogusers = get_users_of_blog();
    if ($blogusers) {
      foreach ($blogusers as $bloguser) {
        $user = new WP_User( $bloguser->user_id );
        if ( !empty( $user->roles ) && is_array( $user->roles ) && ( in_array('author',$user->roles) ) ){
          //echo "<pre>"; print_r($user); echo "</pre>";
          echo '<p>User ID ' . $user->data->ID . ' ' . $user->data->user_firstname . ' ' . $user->data->user_lastname . '</p>';
            'author' => $user->data->ID,
            'post_type' => 'post',
            'post_status' => 'publish',
            'posts_per_page' => 2,
            'caller_get_posts'=> 1
          $my_query = null;
          $my_query = new WP_Query($args);
          if( $my_query->have_posts() ) {
            echo 'List of Posts for this user';
            while ($my_query->have_posts()) : $my_query->the_post(); ?>
              <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
          wp_reset_query();  // Restore global post data stomped by the_post().

    Thanks for the reply, but, in case of the code above it defines one author and list 2 posts of him.

    What I need is list the last 2 posts posted by author’s role, and not the last 2 posts of one only author.

    See my website in the link below:

    In the section “Artigos Mais Recentes de Counistas” – “Most Recente Articles from Columnists” I want to list the most recente posts from my columnists, that were registered at admin like “Authors”.

    The rest content of my website are posted by me, and I am the Admin of it. This is the why I don’t need my posts listed in that section, becouse that section is only to list the Columnists “Authors” posts.

    Is now easier to understand what I need?

    Sorry if I not explained better before!

    Well that code lists each user of the Author Role and two posts (if there are two posts).

    Oh well maybe someone else can jump in here with a better solution. Good Luck.

    MichaelH, in your code how can I limit to show only 2 posts a time?

    Becouse in your code, if I have 10 Authors, it shows the 10 authors last post. I need to show Only the last 2 independing the total of authors.

    Can you help me?

    Then you’d need to capture the ID of the author users in an array that are ‘authors’, then do a query posts loop and check to see if the author of each post was part of your author array.

    I can’t do your last reply, help me!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘List posts only from authors level?’ is closed to new replies.