$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>theme development - How to display latest posts with authors image|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

theme development - How to display latest posts with authors image

matteradmin7PV0评论

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 badges
Add a comment  | 

1 Answer 1

Reset to default 0

You 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

Post a comment

comment list (0)

  1. No comments so far