WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: Multiple Post Thumbnails] Image not displaying (20 posts)

  1. zeckdude
    Member
    Posted 4 years ago #

    I can get the Secondary Image Upload box to show up in the admin area, but I can't manage to get the image to display on the page.

    This is the code I am using to try and make it display (From: http://wordpress.org/extend/plugins/multiple-post-thumbnails/installation/):

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image'); endif; ?>

    I tried adding a random echo inside the if statement to see if it gets hit, but it doesn't echo out, so i'm guessing somehow the condition is not being met?

    What am I missing?

  2. Drew Gourley
    Member
    Posted 4 years ago #

    make sure that the post type matches up with the post type you declared when you register the post thumbnails.

    The author shows

    $thumb = new MultiPostThumbnails(array(
        'label' => 'Secondary Image',
        'id' => 'secondary-image',
        'post_type' => 'page'
        )
    );

    but then incorrectly tells you to put this in the template:

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image'); endif; ?>

    if you registered it as post-type => page, then you'd have to use:

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('page', 'secondary-image')) :
            MultiPostThumbnails::the_post_thumbnail('page', 'secondary-image'); endif; ?>

    This got it all working for me.

    Don't forget, this is really versatile! You could literally register ten or more post-thumbnails by giving them unique identifiers when registering them. Exciting stuff!

  3. zeckdude
    Member
    Posted 4 years ago #

    Drew, thanks for the response. I appreciate the help!

    I changed the code as you suggested and it didn't change anything unfortunately.

    Here is everything I have done with this plugin:

    I am using the twentyten theme as a parent them for a new theme I'm making.

    I activated the plugin.

    I put this in my functions.php file:

    $thumb = new MultiPostThumbnails(array(
        'label' => 'Secondary Image',
        'id' => 'secondary-image',
        'post_type' => 'page'
       )
    );

    I put this in my page.php file:

    if (class_exists('MultiPostThumbnails') && MultiPostThumbnails::has_post_thumbnail('page', 'secondary-image')) :
                        echo 'This condition is met';
                        MultiPostThumbnails::the_post_thumbnail('page', 'secondary-image'); endif;

    It said 'post' before, and I changed it to 'page' now, but that does not fix the problem.

    I uploaded an image, I can see the image uploads, it adds a new custom field with the name 'post_secondary-image_thumbnail_id' and the correct id number(i checked the database and it inserts the image location correctly).

  4. Drew Gourley
    Member
    Posted 4 years ago #

    Sorry to hear that this didn't work, but there is one difference between yours and mine. I changed the way the condition was formatted. This is a long shot, because everything you've done SHOULD make it work, but it hasn't... Here is the exact code from my page.php:

    <?php if (class_exists('MultiPostThumbnails') && MultiPostThumbnails::has_post_thumbnail('page', 'secondary-image')) { ?>
    <div id="secondaryImage">
    	<?php MultiPostThumbnails::the_post_thumbnail('page', 'secondary-image'); ?>
    </div>
    <?php } ?>

    And the div isn't necessary, its for CSS so:

    <?php if (class_exists('MultiPostThumbnails') && MultiPostThumbnails::has_post_thumbnail('page', 'secondary-image')) {
      MultiPostThumbnails::the_post_thumbnail('page', 'secondary-image');
    } ?>
  5. Abdussamad Abdurrazzaq
    Member
    Posted 4 years ago #

    Zeckdude I had the same problem as you and I figured out how to fix it. Just omit the "$thumb =" part. You don't have to assign the object to any variable. Put the following in functions.php:

    new MultiPostThumbnails(array(
        'label' => 'Secondary Image',
        'id' => 'secondary-image',
        'post_type' => 'page'
       )
    );
  6. Drew Gourley
    Member
    Posted 4 years ago #

    Ha, nice.

    Really odd is that it works for me both ways...

  7. zeckdude
    Member
    Posted 4 years ago #

    I had not placed my code inside the loop for the content for that particular page. Rookie Mistake!

  8. TakeoK
    Member
    Posted 3 years ago #

    redacted

  9. casper83
    Member
    Posted 3 years ago #

    worked with me when i entered the post id

    if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('page', 'secondary-image',$post->ID)) :
        MultiPostThumbnails::the_post_thumbnail('page', 'secondary-image', $post->ID, 'fifth-image');
        endif;
  10. Vitaliy Sopko
    Member
    Posted 3 years ago #

    worked with me when i entered the post id

    Yeah, it works for me too! Thank you, casper83! Nice solution.

  11. www.agentstaobao.com
    Member
    Posted 3 years ago #

    Yeah, it works for me too! Thank you, casper83! Nice solution.

  12. paul-g
    Member
    Posted 3 years ago #

    Yeah, it works for me too! Thank you, casper83! Nice solution.

  13. themagiclaundry
    Member
    Posted 3 years ago #

    hello,

    where in functions.php do i put this code?

    $thumb = new MultiPostThumbnails(array(
        'label' => 'Secondary Image',
        'id' => 'secondary-image',
        'post_type' => 'page'
       )
    );

    i tried putting it on the top of the page and at the bottom and i get errors.

  14. flick
    Member
    Posted 3 years ago #

    @themagiclaundry: This has to go between <?php and ?>

  15. themagiclaundry
    Member
    Posted 3 years ago #

    so i was able to get the code inserted without errors now. when i goto posts, i see the secondary featured image. and i click "set as featured" or "set as secondary" but no matter what, no picture will appear on my page.

    the only way i can get an image to appear is if i use the "Featured" custom field. but that only allows me 1 picture per posts

  16. flick
    Member
    Posted 3 years ago #

    Have you also used the template code for e.g. single.php?

    The code in functions.php helps WordPress recognise that it is a second featured image. The template code asks WordPress to display it.

  17. themagiclaundry
    Member
    Posted 3 years ago #

    i've read a couple posts and i tried many various versions of codes. Here is what i have so far in my functions.php
    [Code moderated as per the Forum Rules. Please use the pastebin]

    and heres what i have in my page.php

    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('page', 'image2')) :
        MultiPostThumbnails::the_post_thumbnail('page', 'image2', NULL, 'post-image2-thumbnail');
        endif; ?>
    
    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('page', 'image3')) :
            MultiPostThumbnails::the_post_thumbnail('page', 'image3', NULL, 'post-image3-thumbnail');
    endif; ?>

    i'm new to wordpress and php. i spent many hours doing trial and errors but nothing worked and would love some guidance. thanks

  18. flick
    Member
    Posted 3 years ago #

    I have slightly different code for functions.php but the template (page.php) code looks similar. This is what I have in functions.php and it does work:

    http://pastebin.com/EqmXQR7i [Edited to use Pastebin - thanks mods]

    I have associated my thumbnails with a custom post type called 'project' but typically it would be page or post.

    Everyone starts somewhere - I'm still learning too!

  19. themagiclaundry
    Member
    Posted 3 years ago #

    just tried to copy and paste that code and changed 'project' to 'post' and no luck. the picture will display in the editor, but when i refresh the site. theres no pictures there. i'm using this in conjunction with the wp-creativx theme. heres my old site, which sucks but is live now. http://themagiclaundry.com and the new site that i'm trying to put up is http://themagiclaundry.com/blog if you notice the 3 picture thats on there now are from 3 separate empty posts with just the "featured" custom field filled out.

  20. flick
    Member
    Posted 3 years ago #

    http://pastebin.com/FXmFpHmQ

    This is what I have in single.php, but I note that you're using 'post' on the functions.php one but 'page' in the template part?

    Very nice looking site btw :)

Topic Closed

This topic has been closed to new replies.

About this Topic