Limit posts per author role (excluding admin) in home page

I have multiple authors in my site and want to show just one, the latest post from each one, excluding the administrator

I have multiple authors in my site and want to show just one, the latest post from each one, excluding the administrators. So, if for example:

  • admin1 has posted 4 posts
  • admin2 posted 3 posts
  • author1 posted 2 and
  • author2 posted 7,

it will show 4 from admin1, 3 from admin2 and 1 from each one of the others. Any hints?

<?php 
get_header(); 
//Displaying latest post per author on front page 
if(have_posts()) : 

    get_template_part('content', 'postlist'); 

else : 
    get_template_part('content', 'none'); 
endif;

get_footer();
?>

I have multiple authors in my site and want to show just one, the latest post from each one, excluding the administrators. So, if for example:

  • admin1 has posted 4 posts
  • admin2 posted 3 posts
  • author1 posted 2 and
  • author2 posted 7,

it will show 4 from admin1, 3 from admin2 and 1 from each one of the others. Any hints?

<?php 
get_header(); 
//Displaying latest post per author on front page 
if(have_posts()) : 

    get_template_part('content', 'postlist'); 

else : 
    get_template_part('content', 'none'); 
endif;

get_footer();
?>
Share Improve this question edited Jan 28, 2016 at 15:33 terminator 6151 gold badge6 silver badges30 bronze badges asked Jan 24, 2016 at 19:58 mausmaus 111 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 1

If I understand your problem then this should definitely work.

<?php 
get_header();

$users = get_users( array( 'who' => 'author' ) );//get all the users with author role in an array


foreach ( $users as $user ) {   //travers the array

    if($user->caps['administrator']==1)continue;     // skip the user if user also have administrative capabilities
$query = new WP_Query( array(
                            'posts_per_page'=>1, 
                            'author' => $user->ID
                            ) 
                    );
if($query->have_posts()):while($query->have_posts()):$query->the_post();

get_template_part('content', 'postlist'); 

endwhile;

else:
get_template_part('content', 'none'); 
endif;

} 

get_footer();
?>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745609953a4635891.html

相关推荐

  • Limit posts per author role (excluding admin) in home page

    I have multiple authors in my site and want to show just one, the latest post from each one, excluding the administrator

    10小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信