WordPress.org

Ready to get started?Download WordPress

Forums

Multiple Post Thumbnails
[resolved] Secondary thumbnail not showing (11 posts)

  1. torquegod
    Member
    Posted 2 years ago #

    Hi Guys,

    Am trying to show the secondary image in my loop on my home page using the following code to first single out the post from a specific category, then retrieve the image from that post -

    <?php query_posts('showposts=1&category_name=featured'); ?>
    <?php if (class_exists('MultiPostThumbnails')
        && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
            MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image'); endif; ?>

    [Please post code or markup snippets between backticks or use the code button.]

    But the image is not showing up. Any ideas why this could be?

    Cheers,

    Rich

    http://wordpress.org/extend/plugins/multiple-post-thumbnails/

  2. torquegod
    Member
    Posted 2 years ago #

    anyone? I still have this problem :(

  3. gaberosser
    Member
    Posted 2 years ago #

    I too am having this issue, but I am just using the basic code give with the Instructions on the Plugin page. Here's my code:

    functions.php:

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

    loop:

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

    I have also tried changing 'post' to 'page' and nothing is working. I am using v3.3.1. Any ideas?

  4. darinroman
    Member
    Posted 2 years ago #

    Anyone get this to work with WP 3.3.1 ?

    I am having the same issue. The meta-box and set image both appear and seem to function properly, however, I cannot get the image to display in my template using the suggested code:

    <?php if (class_exists('MultiPostThumbnails')
    	    && MultiPostThumbnails::has_post_thumbnail('page', 'secondary-image')) :
    	        MultiPostThumbnails::the_post_thumbnail('page', 'secondary-image'); endif; ?>
  5. gaberosser
    Member
    Posted 2 years ago #

    I solved my issue by using this plugin instead:

    http://wordpress.org/extend/plugins/attachments/

    Never did get the Multi-Post Thumbs to work, but this one works for me like a charm!

  6. darinroman
    Member
    Posted 2 years ago #

    Thank you @gaberosser,

    The Attachments plugin looks promising for use in other projects. I really like this featured image functionality to make it really simple for a client to choose a Page Header Image on a page by page basis.

    What I have discovered is that the output does not work outside of the loop, which is where my page header resides. When I placed the template code within the loop it pulls in the image. Now, I have to figure out how to get the image when outside of the loop.

    I've tried this but cannot get it to work, still learning PHP. Does anyone know how I can properly call the MultiPostThumbnail when outside of the loop? Here is what I am trying in my template:

    <?php get_header(); ?>
    
    <div id="content" class="clear">
    
    <?php global $wp_query;
    $postid = $wp_query->post->ID;
    $post_type = get_post_type($postid);
    get_post($postid) ;?>
    
    <div id="page-header">
    <?php
    if (class_exists('MultiPostThumbnails')
    && MultiPostThumbnails::has_post_thumbnail($post_type, 'page-header-image')) :
    MultiPostThumbnails::the_post_thumbnail($post_type, 'page-header-image', NULL, 'Page Header');
    else : ?><img src="http://myblog.com/images/fallback-image.jpg" height="200" width="936" alt="San Francisco Skyline"/>
    <?php endif; ?>
    </div>
    
    <?php wp_reset_query(); ?>
    
    <div id="main-content">
    
    <div id="breadcrumbs"><?php if ( function_exists('yoast_breadcrumb') ) { yoast_breadcrumb();} else { the_breadcrumb();} ?></div>
    
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    <!--Page or Post Content-->
    
    <?php endwhile; endif; ?>
    
    </div><!--END #main-content -->
    
    <?php get_sidebar(); ?>
    
    </div><!--END #content -->
    
    <?php get_footer(); ?>
  7. darinroman
    Member
    Posted 2 years ago #

    I've finally got this working the way I had planned. Here is how I am implementing this plugin in my theme to have a different page header image on each 'post/page/custom post' with a fallback image if not specified:

    In functions.php:

    add_image_size( 'Page Header', 936, 200, true ); 
    
    if (class_exists('MultiPostThumbnails')) {
        $types = array('post', 'page', 'tribe_events');
        foreach($types as $type) {
            new MultiPostThumbnails(array(
                'label' => 'Page Header Image',
                'id' => 'page-header-image',
                'post_type' => $type
                )
            );
        }
    }

    I've altered my original query and specified the post ID in the output according to a solution in a previous thread by 'brubrant' which can be found here: http://wordpress.org/support/topic/plugin-multiple-post-thumbnails-display-thumbnails-outside-loop

    In the post/page/custom post template:

    <?php global $wp_query;
    $postid = $wp_query->post->ID;
    $posttype = get_post_type($postid); ?>
    
        <div id="page-header">
    	<?php
    	if (class_exists('MultiPostThumbnails')
    	    && MultiPostThumbnails::has_post_thumbnail($posttype, 'page-header-image', $postid)) :
    	        MultiPostThumbnails::the_post_thumbnail($posttype, 'page-header-image', $postid, 'Page Header');
        	else : ?><img src="http://myblog.com/images/fallback-image.jpg" height="200" width="936" alt="San Francisco Skyline"/>
    	<?php endif; ?>
        </div>
    
        <?php wp_reset_query(); ?>
    
    <!-- STANDARD PAGE OR POST TEMPLATE WITH LOOP -->
  8. Chris Scott
    Member
    Plugin Author

    Posted 2 years ago #

    FYI, it would be a little cleaner to use get_queried_object_id() to get the post ID.

  9. darinroman
    Member
    Posted 2 years ago #

    Thank you Chris.

  10. ross.edman
    Member
    Posted 1 year ago #

    Has anyone got this working in 3.3.2 or am I doing it wrong? When installing the plugin I don't even get custom fields showing up in the backend. I've gone through the documentation and everything....

    Thanks for all the info above, pretty much all I could find on the subject right now.

  11. Chris Scott
    Member
    Plugin Author

    Posted 1 year ago #

    @ross.edman can you post your code where you register the thumbnails in functions.php?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic