for latest 5 post you can use this code:
$args = array('post_type'=>'post', 'posts_per_page'=> 5);
$query = new WP_Query($args);
if($query->have_posts()):
while($query->have_posts()):$query->the_post();
echo '<li>';
$content = get_the_excerpt();
//for featured image
if(has_post_thumbnail()):
the_post_thumbnail();
endif;
print $content;
echo '</li> ';
endwhile;
wp_reset_postdata();
endif;
In case you want to change word count in excerpt use this action hook function.
/**
* Filter the except length to 20 words.
*
* @param int $length Excerpt length.
* @return int (Maybe) modified excerpt length.
*/
function wpdocs_custom_excerpt_length( $length ) {
return 20;
}
add_filter( 'excerpt_length', 'wpdocs_custom_excerpt_length', 999 );
In case you need to change read more text.
/**
* Filter the “read more” excerpt string link to the post.
*
* @param string $more “Read more” excerpt string.
* @return string (Maybe) modified “read more” excerpt string.
*/
function wpdocs_excerpt_more( $more ) {
return sprintf( '<a class="read-more" href="https://wordpress.stackexchange.com/questions/277240/%1$s">%2$s</a>',
get_permalink( get_the_ID() ),
__( 'Read More', 'textdomain' )
);
}
add_filter( 'excerpt_more', 'wpdocs_excerpt_more' );
hope this will help!