Multiple featured image thumbnails for post types (Multiple Post Thumbnails plugin)

I found a plugin called Multiple Post Thumbnails and followed the directions in getting it set up. Everything shows up correctly in the admin dashboard (i.e. shows two sections to upload two separate thumbnails) but after I set the two thumbnails for each post and view the page which displays those posts, only the first post I set the thumbnails for show up.

This is the code I used in my theme’s functions.php:

$thumb = new MultiPostThumbnails(
    array(
    'label' => 'Larger Image',
    'id' => 'image2',
    'post_type' => 'projects'
    )
);

And here is my Projects page which is the page where the posts are displayed:

<section id="content">

        <section id="projects-list">
            <?php
                $c=0;
                $i=1;

                $temp = $wp_query;
                $wp_query = null;
                $wp_query = new WP_Query();
                $wp_query->query('post_type=projects' . '&paged=' . $paged . '&posts_per_page=6');

                while ( $wp_query->have_posts() ) : $wp_query->the_post(); $c++;
            ?>

            <article class="post<?php if($i%3 == 0) { echo ' right'; }; $i++; ?>" id="post-<?php the_ID(); ?>">
                <section class="entry">
                    <a href="https://wordpress.stackexchange.com/questions/9708/<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>">
                        <?php
                            if (class_exists('MultiPostThumbnails')
                            && MultiPostThumbnails::has_post_thumbnail('projects', 'secondary-image')) :
                            MultiPostThumbnails::the_post_thumbnail('projects', 'secondary-image');
                            endif;
                        ?>
                    </a>
                </section>
                <section class="description">
                    <h2><a href="https://wordpress.stackexchange.com/questions/9708/<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
                    <time class="post-date" datetime="<?php the_time('c'); ?>"><?php the_time('F j, Y'); ?></time>
                </section>
            </article>

            <?php
                endwhile; 
                wp_pagenavi();
                $wp_query = null;
                $wp_query = $temp;
                wp_reset_query();
            ?>

            <?php if( $c < 6 ) : for ($dummy= $c; $dummy < 6; $dummy++) : ?>

                <article class="post<?php if($i%3 == 0) { echo ' right'; }; $i++; ?>" id="post-<?php the_ID(); ?>">
                    <img src="<?php bloginfo('template_url'); ?>/images/dummy-post.gif" alt="Post coming soon!" />
                </article>

                <?php endfor;?>

            <?php endif;?>
        </section>

        <section id="map">
            <img src="<?php bloginfo('template_url') ?>/images/interactive-map.jpg" alt="Interactive Map" />
        </section>

        <section id="youtube-subscribe">
            <iframe id="fr" src="http://www.youtube.com/subscribe_widget?p=mysteryguitarman"></iframe>
        </section>

</section>

Here is a screenshot of what the page looks like. Note only “Project 6” has the thumbnail showing (Project 6 was the first post I uploaded a second thumbnail to) when I uploaded second thumbnails for each of those posts.

Projects Page

Does anybody have experience with this plugin? Also, would anyone suggest an alternative no-plugin way to achieve the same thing? Basically, I just want to be able to upload two separate thumbnails for each post in the Projects post type so one shows on the home page and another (larger) one shows on the Projects page. An ideal setup would be to have just one large image I upload which gets shown on the Projects page and it would automatically get cropped into a smaller thumbnail which I can then use for the home page. Anyhow, any advice/help would be much appreciated. Thank you for reading this long post!

3 Answers
3

Dude, you’re doing this the hard way. You can do what you want totally with a single ‘featured post thumbnail’. Read the documentation about thumbnail sizes in themes. You can inject custom thumbnail sizes in your themes funcitons.php and then give them as a parameter to the (get_)the_post_thumbnail() function. Please just read the documentation at the Codex – start with the function reference page for the_post_thumbnail(), maybe – and you’ll see. WordPress does automatically resize and crop the image for you, if only you tell it to do so.

Leave a Comment