1

(I've already opened a thread on stack overflow: https://stackoverflow.com/questions/30079269/wp-dynamic-featured-image-cant-get-second-featured-image-url Hope it's not considered as double)

I'm actually working on a wordpress website with a Dessign.net theme (the pixel one) which got a beautiful full-page slider on the front page. The slider shows the featured image of selected posts (post for which i've checked "show in slideshow" in the meta box field on edit page).

Those featured image are used in the same way for different view on the site (eg. thumbnails). I need them for the thumbnails, but i'ld like another image (still relative to selected posts) for the home-page slider.

I've found that "Dynamic Featured Image" plugins for wordpress but now i can't achieve to get the second featured image url in the slider's loop.

Here's the part of code for the slider, as it was with the theme:

<ul>
        <?php
        $slider_arr = array();
        $x = 0;
        $args = array(
             //'category_name' => 'blog',
             'post_type' => 'post',
             'meta_key' => 'ex_show_in_slideshow',
             'meta_value' => 'Yes',
             'posts_per_page' => 99
             );
        query_posts($args);
        while (have_posts()) : the_post();



             $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'full' );
            //$thumb = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'large' );
            $img_url = $thumb['0'];
        ?>
            <li data-background="<?php echo $img_url; ?>" onclick="location.href='<?php the_permalink(); ?>';" style="cursor:pointer;">

            </li>
        <?php array_push($slider_arr,get_the_ID()); ?>
        <?php $x++; ?>
        <?php endwhile; ?>
        <?php wp_reset_query(); ?>

    </ul>

Now i've tried to put the code found on the plugin github page:

if( class_exists('Dynamic_Featured_Image') ) {
               global $dynamic_featured_image;
              $thumb = $dynamic_featured_image->get_featured_images( );

                        //You can now loop through the image to display them as required

              }

in place of $thumb = wp_get_attachment_image_src( get_post_thumbnail_id(get_the_ID()), 'full' );

But $thumb return array as a string

I tried a few different things but i'm not fluent in php.

Hope this is understandable.

  • Have you tried: $thumb = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ? – Samuel Elh May 7 '15 at 14:35
  • @samuel thanks but this would get me the thumbnail of the original featured image, but i need the second one i added with the Dynamic Featured Image plugin. – mada May 7 '15 at 15:04
  • Sorry about that. Is $img_url returning the DFI image URL? – Samuel Elh May 7 '15 at 15:10
  • Excuse me but where should i put that ? – mada May 7 '15 at 15:32
  • 1
    I'll try that as soon as i can, but i'm really not sure about it – mada May 7 '15 at 16:16
1

To get featured images of specific post/page use these below code -

if( class_exists('Dynamic_Featured_Image') ) {
     global $dynamic_featured_image;
     $featured_images = $dynamic_featured_image->get_featured_images( $postId );

    //You can now loop through the image to display them as required
 }

Please follow this link - https://github.com/ankitpokhrel/Dynamic-Featured-Image/wiki/Retrieving-data-in-a-theme

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.