samedi 6 février 2016

Show featured images of recent posts in Wordpress?

I have created a very simple plugin for my Wordpress site to display links to my most recent posts with the use of a shortcode ([recentposts]). The plugin works so far but I am struggling with finding a way to display the featured image for each post that is called in the tags for each post link.

Can you please advise how I may do this. The code for my plugin is as follows:

<?php
/*
Plugin Name: Blog Display Blocks
Description: Plugin to display blog posts in block with shortcode
Author: Chris Brosnan
*/

function RecentPosts() {
    $recent_posts = wp_get_recent_posts(6);
    echo '<div class="blog-contain">';
    foreach( $recent_posts as $recent ){
        echo '<div class="third-box"><a href="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</a> </div> ';
    } 
};

echo '</div>';
add_shortcode('recentposts', 'RecentPosts');

register_activation_hook( __FILE__, array( 'Blogdisplay', 'plugin_activation' ) );
register_deactivation_hook( __FILE__, array( 'Blogdisplaym', 'plugin_deactivation' ) );

?>

What would I need to do in order to show the featured image alongside the corresponding link for each post that is called?

Many thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire