1
votes

I would really appreciate any help on that issue. I'd like to display a second thumbail in recent posts section at the bottom of each single post template.

I'm using multipost thumbnails plug-in for wordpress. https://github.com/voceconnect/multi-post-thumbnails

and I'm using this code in my bottom widget area, which is working fine, but instead of a secondary image of each recent post, it shows a secondary image of a current post from above.

<?php $recent_posts = wp_get_recent_posts(55);
foreach( $recent_posts as $recent ){
if($recent['post_status']=="publish"){
if ( has_post_thumbnail($recent["ID"])) { 
echo  '<div id="main-grid">'
. '<a href="' . get_permalink($recent["ID"]) 
. '" title="Look '.esc_attr($recent["post_title"]).'" >'
.   get_the_post_thumbnail($recent["ID"], 'large-thumb') 
.   MultiPostThumbnails::get_the_post_thumbnail('post','secondary-image')
. '<header class="entry-header"><h1>' 
.  $recent ["post_title"]
. '</h1></header>'
. '</a></div> ';
} 
}
}
?>
1
I think you can use $secondary_image_url = MultiPostThumbnails::get_post_thumbnail_url('post','secondary-image'); to get the url for the secondary image. - Cyclonecode
@Cyclone this also gets the URL from Current post from above, not the recent post from the bottom. How to specify to get the $recent post image - KMS

1 Answers

0
votes

You did not hand over the $recent["ID"] to the MultiPostThumbnails function

<?php 
$recent_posts = wp_get_recent_posts(55);
foreach( $recent_posts as $recent ){
    if($recent['post_status']=="publish"){
        if ( has_post_thumbnail($recent["ID"])) {
            echo  '<div id="main-grid">'
            . '<a href="' . get_permalink($recent["ID"])
            . '" title="Look '.esc_attr($recent["post_title"]).'" >'
            .   get_the_post_thumbnail($recent["ID"], 'large-thumb')
            .MultiPostThumbnails::get_the_post_thumbnail(
                'post',
                'secondary-image',
                $recent["ID"],
                'large-thumb'
            )
            . '<header class="entry-header"><h1>'
            .  $recent ["post_title"]
            . '</h1></header>'
            . '</a></div> ';
        }
    }
}
?>

Here you can find the function signature of get_the_post_thumbnail().