Below code might make more sense. I want “bg1” featured image 1, “bg2” featured image 2, so on…
<?php
global $dynamic_featured_image;
$featured_images = $dynamic_featured_image->get_featured_images( );
?>
<?php foreach($featured_images as $images) {?>
<div id="bg1" style="background-image:url(<?php echo $images['full']; ?>)"><?php }?></div>
<div id="bg2" style="background-image:url(<?php echo $images['full']; ?>)"><?php }?></div>
<div id="bg3" style="background-image:url(<?php echo $images['full']; ?>)"><?php }?></div>
Hi @designvibe,
Sorry for late response. Did you solved the issue already or still need help? You can find full list of API here.
Regards,
Ankit
Hi Ankit,
I’m having the same issue – any help on how to do this? Designvibe’s code above makes sense but doesn’t seem to work. What am I doing wrong?
Thanks!
Hi @jordanluckett,
Can you please elaborate on what do you mean by it doesn’t seem to work. Do you get list of images in $featured_images variable?
Regards,
Ankit
Hi Ankit,
Thanks for your response. No, I’m not getting a list of images. Where would I see the list?
Basically, I want to assign featured image 1 to div 1 background, featured image 2 on div 2 background, featured image 3 on div 3 background and so on… How do I do this on a page?
Thanks so much!
Hey there – I am now able to see the list of images in the array now. I feel like I’m so close to making this work. Ho do I reference a specific image to use as the background-image for a specific div. Hope this makes sense.
Thanks,
Jordan
Hi @jordanluckett,
Sorry for late response. Did you managed to get it work? Referencing specific image as your background-image depends entirely on your code structure. Can’t say anything without looking into it. Let me know if you need any help.
Regards,
Ankit
How do you actually split these images up into separate divs?
<?php
global $dynamic_featured_image;
$featured_images = $dynamic_featured_image->get_featured_images( );
?>
<?php foreach($featured_images as $images) {?>
<div class="1"><img src="<?php echo $images['full']; ?>" /></div>
<div class="2"><img src="<?php echo $images['full']; ?>" /></div>
<?php }?>
Thanks
Hi Ankit,
Sorry for the delay. I unfortunately still haven’t be able to get this working. Here’s an example of what I want to do.
Say I have a layout in part of a template that has 6 divs that I want to set the background image to (using your plugin) from a particular post – in this case 230. In post 230 I have added the 6 featured images. Now, I want to add featured image 1 to box 1 div background image, featured image 2 to box 2 div background image and so on a so forth… How do I do this by referencing each image in the array? Does this make sense? Here is an example:
<?php
if( class_exists(‘Dynamic_Featured_Image’) ) {
global $dynamic_featured_image;
$featured_images = $dynamic_featured_image->get_featured_images( 230 );
//You can now loop through the image to display them as required
}
?>
<div class=”row”>
<div class=”large-12 columns”>
<div class=”box1-container”>
<div class=”box1″ style=”background-image: url(‘<?php echo $featured_images[0]; ?>’);”>
</div>
</div>
</div>
</div>
<div class=”row”>
<div class=”large-12 columns”>
<div class=”box2-container”>
<div class=”box2″ style=”background-image: url(‘<?php echo $featured_images[1]; ?>’);”>
</div>
</div>
</div>
</div>
…
Thank you so much in advance!
Cheers,
Jordan
Hey Ankit – any help on this? Trying to get this to work for a client project.
Thank you SO much in advance!
Hi @jordanluckett,
Try something like this:
<?php
if( class_exists('Dynamic_Featured_Image') ) {
global $dynamic_featured_image;
$second_featured_image = $dynamic_featured_image->get_nth_featured_image( 2 );
$third_featured_image = $dynamic_featured_image->get_nth_featured_image( 3 );
}
?>
<div class="row">
<div class="large-12 columns">
<div class="box1-container">
<div class="box1" style="background-image: url('<?php echo $second_featured_image['full']; ?>');">
</div>
</div>
</div>
</div>
<div class="row">
<div class="large-12 columns">
<div class="box2-container">
<div class="box2" style="background-image: url('<?php echo $third_featured_image['full']; ?>');">
</div>
</div>
</div>
</div>
Regards,
Ankit
Awesome! Works perfectly!
THANK YOU!!
@jordanluckett: Glad to know that it worked! A plugin review would be a great help π