Support » Plugin: Dynamic Featured Image » Works great with a little code

  • I got the free version working perfectly last night with WordPress 5.7.

    The description says the plugin will “add any number of featured images … without writing a single line of code”, which is a bit misleading. The plugin provides a GUI interface to flag images as featured, but to actually have the images appear on your site you need to write some code.

    Stack Overflow to the rescue. I found this snippet there and got it working:

     if( class_exists('Dynamic_Featured_Image') ) {
        global $dynamic_featured_image;
    
        $featured_images = $dynamic_featured_image->get_featured_images( );
        //print_r($featured_images);
    
        //You can now loop through the image to display them as required
        foreach($featured_images as $featured_image) {
            echo "<img src='".$featured_image['full']."'>";
        }
    
     }

    Detailed instructions for those who, like me, don’t know PHP at all:

    1. Go to Appearance/Theme Editor
    2. Double click on the part of the site you want to add featured images. This will probably be ‘Single Page’ or ‘Single Post’, but it could be ‘Theme Header’, ‘Theme Footer’, or whatever.
    3. For most pages, you’ll want to paste the above code into ‘the loop’. If you don’t know what ‘the loop’ is, it’s worth looking in to, as it’s probably a bit different on different themes. On most themes, pasting the code anywhere between while (have_posts()): the_post(); and endwhile; should work. But where you put it in relation to other things in ‘the loop’ probably matters.
    4. Note that everything between the quotes, after the word ‘echo’ in the code above is what will appear on your page. So any other stuff you want to add (list items, div tags, etc.) needs to go in there.
    5. If you’re adding any attributes, use single quotes or your whole site will bork.
    6. Have fun!

    Hope that helps. And thank you, Ankit, for a great plugin!

    • This topic was modified 3 months, 2 weeks ago by clarke77.
    • This topic was modified 3 months, 2 weeks ago by clarke77. Reason: adding another code example
    • This topic was modified 3 months, 2 weeks ago by clarke77. Reason: removing code example that didn't display well
  • You must be logged in to reply to this review.