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
1 Answer
Reset to default 1If 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
评论列表(0条)