3
votes

I need to make a RecentPost Carousel in Wordpress with PHP and BxSlider, but I can't get it to show the thumbnail.

I have the recent post with the next code:

    <?php
    $recent_posts = wp_get_recent_posts();
    foreach( $recent_posts as $recent ){
        echo '<li><a href="' . get_permalink($recent["ID"]) . '">' .   $recent["post_title"].'</a> </li> ';
    }
    wp_reset_query();
    ?>

This code shows the last post and is perfectly working, but how can I get the featured image or thumbnail or image from the media library?

2

2 Answers

0
votes

try this -

<?php
$args = array(
    'numberposts' => 10, //number of post.
    'post_type' => 'post',
    'post_status' => 'publish'
);
$recent_posts = wp_get_recent_posts();
foreach( $recent_posts as $recent ){
    echo '<li><a href="' . get_permalink($recent["ID"]) . '">' .get_the_post_thumbnail( $recent["ID"], 'thumbnail' ).   $recent["post_title"].'</a> </li> ';
}
wp_reset_query();
?>
0
votes

Have you tried these?

get_the_post_thumbnail( $post_id, 'thumbnail' );      // Thumbnail (Note: different to Post Thumbnail)
get_the_post_thumbnail( $post_id, 'medium' );         // Medium resolution
get_the_post_thumbnail( $post_id, 'large' );          // Large resolution
get_the_post_thumbnail( $post_id, 'full' );           // Original resolution

https://developer.wordpress.org/reference/functions/get_the_post_thumbnail/

or this?

//Default WordPress
the_post_thumbnail( 'thumbnail' );     // Thumbnail (150 x 150 hard cropped)
the_post_thumbnail( 'medium' );        // Medium resolution (300 x 300 max height 300px)
the_post_thumbnail( 'medium_large' );  // Medium Large (added in WP 4.4) resolution (768 x 0 infinite height)
the_post_thumbnail( 'large' );         // Large resolution (1024 x 1024 max height 1024px)
the_post_thumbnail( 'full' );          // Full resolution (original size uploaded)

https://developer.wordpress.org/reference/functions/the_post_thumbnail/