3

I have recently installed Dynamic Featured Image plugin for wordpress. But I do not know how to link images. I'm trying to create me a gallery like this http://www.subcreative.com.au/#work - Scroll down to the projects and you will see .

I have put this code in functions.php

<?php
 while ( have_posts() ) : the_post();

   if( function_exists('dfi_get_featured_images') ) {
       $featuredImages = dfi_get_featured_images();

       //Now, loop through the image to display
   }

   endwhile;
?>

and used this to link the image.

echo ' <a class="fancybox" href="'. dfi_get_featured_images() .'" style="text-align:center">Take a look</a> '; ?>

But when I try to open the image, it becomes "/array"

Konsole
  • 3,447
  • 3
  • 29
  • 39
Wezzou
  • 37
  • 1
  • 6
  • The error is telling you where to look. You need to select an item from within an array that's been created. You might need to upload more code than this for us to help, looks like theres other PHP somewhere that's talking to this, for example the code for dfi_get_features_images() function – Andy Holmes Nov 16 '13 at 17:10

3 Answers3

5

Im not a wordpress dev but I've seen this on the wordpress website that I tried to fix. so maybe you can try this one.

if( class_exists('Dynamic_Featured_Image') ):
    global $dynamic_featured_image;
    global $post;
     $featured_images = $dynamic_featured_image->get_featured_images( $post->ID );

     if ( $featured_images ):
        ?>
            <?php foreach( $featured_images as $images ): ?>
               <img src="<?php echo $images['full'] ?>" alt="">
            <?php endforeach; ?>
        <?php
        endif;
endif;

this works in my case. I'm using DFI 3.1.13

blitzen12
  • 1,350
  • 3
  • 24
  • 33
2

This answer is only valid for plugin version 2.0.2 and below.

You need to loop throught the returned array and display the image manually. Try this:

<?php   

    if( function_exists('dfi_get_featured_images') ) {
       $featuredImages = dfi_get_featured_images();

       //Loop through the image to display your image

       if( !is_null($featuredImages) ){

            $links = array();

            foreach($featuredImages as $images){
                $thumb = $images['thumb'];
                $fullImage = $images['full'];

                $links[] = "<a href='{$fullImage}' class='dfiImageLink'><img src='{$thumb}' /></a>";
            }

            echo "<div class='dfiImages'>";
            foreach($links as $link){
              echo $link;
            }                
            echo "</div>";
         }        
    }

?>
Konsole
  • 3,447
  • 3
  • 29
  • 39
  • Where do I put this in ? Functions.php ? My CPT ? – Wezzou Nov 16 '13 at 17:32
  • You need to put this in the place where you want to display the images. For example if you want to display images in the main index page you can use this code (without outer while loop) inside `index.php`` just after the statement ``. – Konsole Nov 16 '13 at 17:40
  • haha, It's create a billion of post when I put the code in to my template. @Console – Wezzou Nov 16 '13 at 17:50
  • I bet you are using loop inside a loop. You just need a single while statement. Remove one while loop. – Konsole Nov 16 '13 at 17:52
  • As i said. You are using a loop inside a loop. Check the answer again. I have removed the while loop from my answer. You are already inside a loop so you don't need that. – Konsole Nov 16 '13 at 18:01
  • Yes, It's work now but same problem .. When I link to the images I've got "/array" at the end of the link when I open it. « Ta en titt »'; ?> – Wezzou Nov 16 '13 at 18:12
  • Do you know how to fix it? @Console – Wezzou Nov 16 '13 at 19:36
  • You are linking it incorrectly. `dfi_get_featured_images()` will return an array. You need to extract the value like `$thumb = $images['thumb']; $fullImage = $images['full'];` and link these values. It is already shown in the answer. – Konsole Nov 17 '13 at 03:44
0

try this inside of have posts loop

$img=dfi_get_featured_images();
$url=$img['full'];
echo ' <a class="fancybox" href="'. $full .'" style="text-align:center">Take a look</a> ';

If full doesn't work try thumb also.

chiliNUT
  • 18,989
  • 14
  • 66
  • 106