Featured Image in Recent Global Posts Widget

Hi,

I need to get featured images on the Recent Global Posts Widget. I know this was a requested feature in the past, I've searched the forum and can't see any updates on that. Is this possible yet? If not I need some help with custom coding to add it.

Thanks in advance!

  • Mike
    • WPMU DEV Initiate

    Hey @dubajicp1

    Thanks but that didn't work. I can't believe that this small feature has been requested for over 2 years now and it still hasn't been added...

    Here's what I did in the end:

    In widget-recent-global-posts.php after this:

    $blog = get_blog_details( $post->BLOG_ID );
    						$blog_title = $blog ? $blog->blogname : '';
    						$title = $substr( $the_title, 0, $recentglobalpoststitlecharacters );
    						$content = $substr( strip_tags( $the_content ), 0, $recentglobalpostscontentcharacters );

    I added this:

    $postID = $post->ID;
    						switch_to_blog(2);
    						$thumbnail = get_the_post_thumbnail( $postID,array(200,200) );
    						restore_current_blog();

    I only want to get posts from blog 2 so this works for me, you might have to try something else here.

    Then I changed this:

    case self::DISPLAY_TITLE_CONTENT:
    							default:
    								echo '<a href="', $the_permalink, '">', $title, '</a>';
    								echo '<br>';
    								echo $content;
    								break;

    To this:

    case self::DISPLAY_TITLE_CONTENT:
    							default:
    								echo '<div class="post-thumbnail"><a href="' . $the_permalink . '">' . $thumbnail . '</a></div>';
    								echo '<a href="', $the_permalink, '">', $title, '</a>';
    								echo '<br>';
    								echo $content;
    								break;

    And it's done and ready to be styled.

    Hopefully this will help someone else who needs this to add featured images to the Recent Global Posts Widget!

    Regards,
    Mike

  • Predrag Dubajic
    • Support

    Hey Mike,

    Awesome stuff there!
    Glad to hear you managed to make this work and thanks for sharing the solution with other members, I'll send some points your way :slight_smile:

    I will also refresh the features list for this plugin so it might speed things up a bit.

    I'll mark this one as resolved but if you have any additional question fell free to reopen it.

    Have a great day,
    Predrag

  • Marco
    • Flash Drive

    Hi, how's the "out of the box" update using Mike's solution? I'm trying to solve the same problem (include product pictures and short description on the feed). Indeed I've found this plug-in that could serve as inspiration for you guys for further developments: https://wordpress.org/support/plugin/post-grid The problem is that it doesn't solve the multisite problem, but to display posts from a single site it's pretty cool.

    Regards,
    Marco

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.