WordPress.org

Ready to get started?Download WordPress

Forums

Dynamic Featured Image
[resolved] Get second featured image (5 posts)

  1. imaginocracy
    Member
    Posted 6 months ago #

    Hi Ankit, thank you for the great plugin. I am sure I am close on this, but I cannot get the second image ONLY to display. I have two featured images on my post; I want to display the second featured image using this code.

    I am using this within a loop.

    if (function_exists('dfi_get_featured_images') ) {
    			$featuredImages = dfi_get_featured_images(1); //get second featured image
    			if( !is_null($featuredImages) ) { //if value is not null
    				echo '<div class="featured-image featured-image-desktop hidden-xs">'; //create featured image wrapper
    				foreach($featuredImages as $images) {
    					echo '<img src="' . $images['desktop'] . "' />";
    				}
    				echo '</div>'//close image wrapper
    
    			}
    		}

    "desktop" is a custom image size I created in my functions.php file.

    https://wordpress.org/plugins/dynamic-featured-image/

  2. imaginocracy
    Member
    Posted 6 months ago #

    Update:

    <?php
    	/** single product featured image (second featured image)
    	 *
    	 */
    
    		if (function_exists('dfi_get_featured_images') ) {
    
    			$featuredImages = dfi_get_featured_images( $returnedArray[1] );
    
    			if( !is_null($featuredImages) ) {
    
    				echo '<div class="featured-image featured-image-desktop hidden-xs">'; // featured image wrapper
    
    				foreach($featuredImages as $images) {
    
    					echo '<img src="' . $images['full'] . '" />';
    
    				}
    
    				echo '</div>';
    
    			}
    		}
    ?>

    This works. Thanks for the great plugin Ankit!

  3. Ankit Pokhrel
    Member
    Plugin Author

    Posted 6 months ago #

    Hello imaginocracy. Thank you for using the plugin. Glad to know that you solved your issue. Additionally this post shows how to get second featured image - http://ankitpokhrel.com.np/blog/fetching-information-from-the-returned-data/.

    Thanks,
    Ankit

  4. Barry Crump
    Member
    Posted 6 months ago #

    Thank you so much imaginocracy

    You code worked perfectly. I'm using this plugin to display a different custom banner for each post and couldn't find any reference on this site to actually displaying the image. It seems to only cover retrieving the data.

    Ankit Pokhrel, you may want to display this snippet of code prominently on your plugin site, I feel like this would be one of the most common usages of your plugin. The ability to insert the secondary featured image anywhere in your theme.

    Awesome, thanks.

  5. imaginocracy
    Member
    Posted 6 months ago #

    Barry, glad I could help, that was a tough nut. Ankit the missing link in your posts is how to use $returnedArray[X]. I had to piece together and troubleshoot my code via probably 4 or 5 different posts to figure it out.

Reply

You must log in to post.

About this Plugin

About this Topic