Support » Plugin: Multiple Featured Images » [Plugin: Multiple Featured Images] Add Img Caption to Output

  • Hello,

    Love this plugin. I’ve got it working to add 3 new featured images to each post. I’ve made it so the images (including the initial featured image) are automatically outputted into the post page in full size. This is great. What we want is to add the captions we add to the image file in the backend to show automatically in the front end. I’ve tried several things but no luck. Here is the code in my single.php file –

    			$thumb = '';
    			$width = 612;
    			$height = 612;
    			$classtext = 'post-thumb';
    			$titletext = get_the_title();
    			$img_desc = post_excerpt;
    			$thumbnail = get_thumbnail($width,$height,$classtext,$titletext,$titletext,false,'Entry');
    			$thumb = $thumbnail["thumb"];
    <?php if($thumb <> '' && get_option('modest_thumbnails_index') == 'on') { ?>
    			<div class="entry-thumbnail">
    					<?php print_thumbnail($thumb, $thumbnail["use_timthumb"], $titletext, $width, $height, $classtext); ?>
    <div class="entry-thumbnail2"><?php if( class_exists( 'kdMultipleFeaturedImages' ) ) {
        kd_mfi_the_featured_image( 'featured-image-2', 'post' );
    } ?></div>
    <div class="entry-thumbnail3"><?php if( class_exists( 'kdMultipleFeaturedImages' ) ) {
        kd_mfi_the_featured_image( 'featured-image-3', 'post' );
    } ?></div>
    <div class="entry-thumbnail4"><?php if( class_exists( 'kdMultipleFeaturedImages' ) ) {
        kd_mfi_the_featured_image( 'featured-image-4', 'post' );
    } ?></div> <?php } ?>

    Any ideas?

Viewing 12 replies - 1 through 12 (of 12 total)
  • Anyone??

    Here’s a function I just made really quick to use it in one of my projects.

    Here’s how you use it:

    <?php echo get_multiple_thumbnail_caption(get_post_meta(get_the_ID(), 'kd_featured-image-3_page_id', 1)); ?>

    The function returns the excerpt (caption) of the thumbnail, so with get_post_meta we retrieve the thumbnail ID by specifying the key “kd_featured-image-3_page_id”, make sure to change this to your own.

    Hope it helped.

    Hi PHPanos, I also need the captions displayed, so many thanks for your solution.
    I have tried to integrate it into my code, but cannot get it to work. I have copied the function into functions.php, and the function call into my template file, as follows:

    <?php if( class_exists('kdMultipleFeaturedImages')) {
    kd_mfi_the_featured_image('featured-image-2', 'page');
    echo get_multiple_thumbnail_caption(get_post_meta(get_the_ID(), 'featured-image-2', true));
    } ?>

    But no luck. Perhaps I have misunderstood the key string? I have used the featured image string, but should it be the page id, such as ‘9’?

    I have tried every combination, and am ready to abandon the plugin which would be a shame.

    Any help appreciated!

    indirectdesign: The function takes the featured-image post id as an argument. Multiple Featured Images plugin stores the featured-image post id in the wp_postmeta table. I used the get_post_meta to retrieve this ID.

    Basically, the get_post_meta should return a post id. Do you even get the featured image to display? Your code looks right.

    If you echo this line:
    get_post_meta(get_the_ID(), 'featured-image-2', true)
    Does it return a post id?

    PHPanos: Many thanks, I’ve managed to get it working! I used the_meta(); to write the key and post id to the page, and what I discovered was that your original key string was literally correct: kd_featured-image-2_page_id (not: featured-image-2). For the third featured image the key would be kd_featured-image-3_page_id and so on.

    I have built the page to include up to 10 images, so for anyone else interested, I combined the code into a for loop, rather than have 20 lines of repetitive code.

    So the code becomes:

    <?php if(class_exists('kdMultipleFeaturedImages')) {
    for ($i = 2; $i <= 10; $i++) {
    kd_mfi_the_featured_image("featured-image-{$i}", "page");
    echo get_multiple_thumbnail_caption(get_post_meta(get_the_ID(), "kd_featured-image-{$i}_page_id", true));
    } ?>

    Of course one also needs to include the code to display the first featured image and its caption, for that see the following post:

    Many thanks again, it is such a relief to have this working!

    I’m glad you managed to solve it 🙂

    I’m looking for this to. And with a lot of re-code I can’t put to work this option.
    Can you please do a resume?


    Pedroooo: How does your function call look like? Where you echo out the caption text…

    PHPanos, thanks for the reply!

    on the single.php I have this:

    <div class="secondary-image">
          <?php  if( class_exists( 'kdMultipleFeaturedImages' ) ) { kd_mfi_the_featured_image( 'featured-image-2', 'post' );
    }; ?>

    and functions.php this:

    if( class_exists( 'kdMultipleFeaturedImages' ) ) {
            $args = array(
                    'id' => 'featured-image-2',
                    'post_type' => 'post',      // Set this to post or page
                    'labels' => array(
                        'name'      => 'Featured image 2',
                        'set'       => 'Set featured image 2',
                        'remove'    => 'Remove featured image 2',
                        'use'       => 'Use as featured image 2',
            new kdMultipleFeaturedImages( $args );

    and i try to change the single.php to this:

    <?php if(class_exists('kdMultipleFeaturedImages')) {
    for ($i = 2; $i <= 10; $i++) {
    kd_mfi_the_featured_image("featured-image-{$i}", "page");
    echo get_multiple_thumbnail_caption(get_post_meta(get_the_ID(), "kd_featured-image-{$i}_page_id", true));
    } ?>

    Are you sure you’re writing the correct key for the caption? Can you check the database if the key kd_featured-image-{$i}_page_id is correct?

    Where I can check that?
    I’m using just that term: ‘featured-image-2’

    I’m a little confuse with this code.
    What should I do?

    Hi pedrooo, don’t know if you managed to solve this but I had the same problem (see above) – it seems you must use the full key string:


    just ‘featured-image-2’ doesn’t work, it has to have ‘_page_id’ after.

    Hope that’s helpful.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘[Plugin: Multiple Featured Images] Add Img Caption to Output’ is closed to new replies.