-1

I have a Multi Author Blog, I want to show Recent post of each user / author. Image has been attached for more convenient, see the Red selected area where author's recent post is showing.

Author Recent post

  • What have you tries so far, what research have you done. Please edit you question and add all relevant code and explain where your code is failing – Pieter Goosen May 29 '14 at 9:33
0

To do this we will need to do 2 queries:

1) Get a list of all the users on the site via wp_user_query

2) Get posts from all the users using wp_query

The code:

$user_query = new WP_User_Query( 'Author' );

if ( ! empty( $user_query->results ) ) {
 foreach ( $user_query->results as $user ) {
  echo '<h2>' . $user->display_name . '</h2>';
  $query1 = new WP_Query( 'posts_per_page=4&author_name='.$user->display_name );
  while ( $query1->have_posts() ) {
   $query1->the_post();
   echo '<p><a href="'.get_permalink().'">'.get_the_title().'</a></p>';
  }
  wp_reset_postdata();
 }
}

It's not tested but it should display like:

Author 1: - Post 1 Post 2 Post 3 Post 4

Author 2: - Post 1 Post 2 Post 3 Post 4

  • Thanks for your effort. I've already user list, i just need each user 5-8 last with thumbnail. – Maan May 29 '14 at 9:44
  • you would use get_the_thumbnail() to get the thumbnail for each post, put it after the $query1 ->the_post() – Gareth Gillman May 29 '14 at 9:48
  • It's difficult for me to add this code in it as I have an author card that have Avator & showing user name as well. Check the screenshot please link Give me only that code which show recent post with image. – Maan May 29 '14 at 14:01
  • Anyone else know. – Maan May 29 '14 at 21:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.