I have installed a plugin that lets me put a PHP code into the widget - basically, what I want to do is to create a "recent posts" area, where you can see a cover of the post (featured image's thumbnail), title and number of comments for them.
So far I managed to create a code that works - minus the comments. I looked at few different things, like get_comments_number, comments_number, wp_count_comments - but so far I can't get this to work.
Here's current code:
<?php $recent_posts = wp_get_recent_posts(array('numberposts' => 3)); ?> <ul> <?php foreach($recent_posts as $post) : ?> <li> <a href="<?php echo get_permalink($post['ID']) ?>"> <?php echo get_the_post_thumbnail($post['ID'], 'thumbnail'); ?> <?php echo $post['post_title'] ?> </a> - //here I want to show the number of comments </li> <?php endforeach; ?> </ul>
Edit: did it myself :D somehow my PHP stopped being saved and after a couple of more tries I managed to find a way. Added this and it seems to work:
<?php echo get_comments_number($post['ID']); ?>