how can U get latest posts from a specific category and post them with the picture of the author. All authors are signed as an author on WordPress and they all have profile picture. Actually it will stand for columns side like this and the system must get latest 1 first then the second and third goes like this...
how can U get latest posts from a specific category and post them with the picture of the author. All authors are signed as an author on WordPress and they all have profile picture. Actually it will stand for columns side like this and the system must get latest 1 first then the second and third goes like this...
Share Improve this question edited Nov 10, 2018 at 19:52 Krzysiek Dróżdż 25.6k9 gold badges53 silver badges74 bronze badges asked Nov 10, 2018 at 13:38 buğracanbuğracan 251 silver badge8 bronze badges1 Answer
Reset to default 0You could try something like this:
<?php
$args = array( 'category' => 12, 'post_type' => 'post' );
$postslist = get_posts( $args );
foreach ($postslist as $post) :
setup_postdata($post);
?>
<h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<h4><?php the_author();?></h4>
<?php
the_excerpt();
echo get_avatar(get_the_author_meta());
endforeach;
?>
In the example the category id is set to 12 - just replace it with the id of the category you want to use.
More info:
How to loop through posts: https://developer.wordpress/reference/functions/get_posts/#user-contributed-notes
How to get the author name: https://codex.wordpress/Function_Reference/the_author
How to get the author image: https://codex.wordpress/Function_Reference/get_avatar