WordPress.org

Ready to get started?Download WordPress

Forums

Dynamic Featured Image
[resolved] Is there an example code to display a specific image? (5 posts)

  1. gian-ava
    Member
    Posted 5 months ago #

    Hi,

    I am trying to use the plugin but without advanced PHP knowledge, there is no way to simply past a function and change the number to display a specific featured image.

    I have read this post: http://wordpress.org/support/topic/get-second-featured-image?replies=5

    But that is so much code just to display one of the images.

    I was hoping that with the plugin something simple like this would be provided:
    if( class_exists('Dynamic_Featured_Image') ) { $image[2] }

    …or something.

    That doesn't seem the case, and even thought you provide a code with a returned arrey, there is no one single example to copy/paste and just change a number (1, for image 1; 2 for image 2; …).

    Am I missing something?

    Any help is highly appreciated.

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

  2. gian-ava
    Member
    Posted 5 months ago #

    Actually, this plugin got the simple function I was looking for:
    http://wordpress.org/support/plugin/multiple-post-thumbnails

    if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'secondary-image');

    You get it by setting it in functions.php:

    if (class_exists('MultiPostThumbnails')) {
            new MultiPostThumbnails(
                array(
                    'label' => 'Secondary Image',
                    'id' => 'secondary-image',
                    'post_type' => 'post'
                )
            );
        }

    You can create as many Featured Images as you want.

    DFI has a better interface functionality, with the "create featured images on the fly", so it would be perfect if you could implement a simpler code to call a single image, in one line of code.

  3. Ankit Pokhrel
    Member
    Plugin Author

    Posted 5 months ago #

    Hello gian-ava,

    There is a function called get_nth_featured_image() available from ver. 3.0.0 .

    Is it what you are looking for?

    Thanks,
    Ankit

  4. gian-ava
    Member
    Posted 5 months ago #

    Hi Ankit, thanks for the feedback.

    I tried "get_nth_featured_image()" with different options, and nothing works:

    get_nth_featured_image(2)
    get_nth_featured_image('2')

    If one wants to call the "Featured Image 2" what is the complete code?

    I honestly think that this is a bit of information that should be clear even before you install the plugin, from the plugin page, instead of digging and guessing for hours.
    Just trying to give you my feedback as a user who's struggling with what should take a few seconds.

    Also, it could be nice for your plugin if you could change the "Featured Image 2", "Featured Image 3", with a custom name, as it could be more coherent with what the image is used for, like "Slider Image", Thumbnail Image", Post Image". That could be a nice add on.

  5. Ankit Pokhrel
    Member
    Plugin Author

    Posted 5 months ago #

    Hello gian-ava,

    Did you tried passing the post id along with the position?
    For example $nth_image = $dynamic_featured_image -> get_nth_featured_image( 3, 5 ); where 3 is the position of the featured image and 5 is the post id. So it will basically fetch the second featured image from the post with an id of 5.

    And thanks for the feature request. Actually that feature is in the to-do list. Future version will allow users to add their custom title as the heading.

    Thanks,
    Ankit

Reply

You must log in to post.

About this Plugin

About this Topic