0

I am having problems getting this plugin to run but have had little success getting it to work, even after reading past entries. I would be grateful if you could see if the code is right.

Code in functions.php:

'// Add secondary thumbnail (featured image) in posts */
if (class_exists('MultiPostThumbnails')) { 
new MultiPostThumbnails(array ( 
        'label' => 'Secondary Image', 
        'id' => 'secondary-image', 
        'post_type' => 'post' )
);
new MultiPostThumbnails(array(
        'label' => 'Tertiary Image',
        'id' => 'tertiary-image', )
 );
new MultiPostThumbnails(array(
        'label' => 'Quaternary Image',
        'id' => 'quaternary-image', )
);
}
add_image_size('post-secondary-image-thumbnail', 176, 58, true);
add_image_size('post-tertiary-image-thumbnail', 176, 58, true);
add_image_size('post-quaternary-image-thumbnail', 176, 58, true);'   

Code in the relevant template (I have posted the whole template code as I think you will need to see it in full):

<?php

/*
    Template Name: Home
*/

?>
<?php get_header(); ?>

<div id='main-content'>

        <h2>What We Do</h2>

        <ul id="we-do">

    <?php query_posts("posts_per_page=1&post_type=page&page_id=168"); 
             the_post (); ?>
        <!--If you want to refer to the child of parent page, use "post_parent=" -->
        <li>
            <h3><?php the_title(); ?></h3>
             <?php the_excerpt(); ?>
             <?php if (class_exists('MultiPostThumbnails')
    && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
    MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image'); endif; ?>
            <a href="<?php the_permalink(); ?>" class="button">View More</a>
        </li>

    <?php query_posts("posts_per_page=1&post_type=page&page_id=236"); the_post(); ?>

        <li>
            <h3><?php the_title(); ?></h3>
            <p><?php the_excerpt(); ?></p>
            <?php if (class_exists('MultiPostThumbnails')
   && MultiPostThumbnails::has_post_thumbnail('post', 'tertiary-image')) :
    MultiPostThumbnails::the_post_thumbnail('post', 'tertiary-image'); endif; ?>
            <a href="<?php the_permalink(); ?>" class="button">View More</a>
       </li>

  <?php query_posts("posts_per_page=1&post_type=page&page_id=240"); the_post(); ?>

        <li>    

            <h3><?php the_title(); ?></h3>
            <?php the_excerpt(); ?>
             <?php if (class_exists('MultiPostThumbnails')
    && MultiPostThumbnails::has_post_thumbnail('post', 'quaternary-image')) :
    MultiPostThumbnails::the_post_thumbnail('post', 'quaternary-image'); endif; ?>
            <a href="<?php the_permalink(); ?>" class="button">View More</a>
      </li>
         </ul>

</div><!--END main-content-->

<?php get_sidebar(); ?>

<?php get_footer(); ?>

I also want apply a class to the images but not sure where to place the array.

It might be important to note that I am also running the Featured Image functionality which is also registered in the functions template.

2 Answers 2

1

Here is a complete example using the code you provided:

For your functions.php file:

<?php
// Add secondary thumbnail (featured image) in posts */
if (class_exists('MultiPostThumbnails')) { 
 new MultiPostThumbnails(array ( 
   'label' => 'Secondary Image', 
   'id' => 'secondary-image', 
   'post_type' => 'post' )
   );
  new MultiPostThumbnails(array(
   'label' => 'Quaternary Image',
   'id' => 'quaternary-image', )
   );
  new MultiPostThumbnails(array(
   'label' => 'Tertiary Image',
   'id' => 'tertiary-image', )
   );
 }
add_image_size('post-secondary-image-thumbnail', 176, 58, true);
add_image_size('post-tertiary-image-thumbnail', 176, 58, true);
add_image_size('post-quaternary-image-thumbnail', 176, 58, true);
?>

And for your page template:

<?php
/*
Template Name: Home
*/
?>
<?php get_header(); ?>
<div id='main-content'>
<h2>What We Do</h2>
  <ul id="we-do">
    <?php 
      query_posts("posts_per_page=1&post_type=page&page_id=168");
      the_post (); ?>
    <!--If you want to refer to the child of parent page, use "post_parent=" -->
    <li>
      <h3><?php the_title(); ?></h3>
        <?php the_excerpt(); ?>
      <?php 
        MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image', NULL,  'post-secondary-image-thumbnail');
      ?>
      <a href="<?php the_permalink(); ?>" class="button">View More</a>
    </li>
    <?php 
      query_posts("posts_per_page=1&post_type=page&page_id=236"); 
      the_post(); 
      ?>
      <li>
        <h3><?php the_title(); ?></h3>
        <p><?php the_excerpt(); ?></p>
      <?php 
        MultiPostThumbnails::the_post_thumbnail('post', 'quaternary-image', NULL,  'post-quaternary-image-thumbnail');
        ?>
        <a href="<?php the_permalink(); ?>" class="button">View More</a>
      </li>
    <?php query_posts("posts_per_page=1&post_type=page&page_id=240"); the_post(); ?>
    <li>
    <h3><?php the_title(); ?></h3>
    <?php the_excerpt(); ?>
    <?php 
      MultiPostThumbnails::the_post_thumbnail('post', 'tertiary-image', NULL,  'post-tertiary-image-thumbnail');
      ?>
    <a href="<?php the_permalink(); ?>" class="button">View More</a>
    </li>
  </ul>
</div><!--END main-content-->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
1
  • I simply copied and pasted the code above but I am finding there is not a option on the WP back-end to select a secondary, tertiary or quaternary image when i select upload image. It only gives the options for a "Featured Image" a the specified dimensions.
    – tobeeornot
    Commented Dec 1, 2011 at 17:02
0

For your code to work you need to change your code to this in the functions.php file:

<?php
// Add secondary thumbnail (featured image) in posts */
if (class_exists('MultiPostThumbnails')) { 
 new MultiPostThumbnails(array ( 
   'label' => 'Secondary Image', 
   'id' => 'secondary-image', 
   'post_type' => 'post' )
   );
  new MultiPostThumbnails(array(
   'label' => 'Quaternary Image',
   'id' => 'quaternary-image', )
   );
  new MultiPostThumbnails(array(
   'label' => 'Tertiary Image',
   'id' => 'tertiary-image', )
   );
 }
add_image_size('post-secondary-image-thumbnail', 176, 58, true);
add_image_size('post-tertiary-image-thumbnail', 176, 58, true);
add_image_size('post-quaternary-image-thumbnail', 176, 58, true);
?>

Then to use the code in the template you would use this:

<?php 
  MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image', NULL,  'post-secondary-image-thumbnail');
  ?>

The thumbnail will automatically add the class of :

.attachment-post-secondary-image-thumbnail

This will change for each additional size you register. It will have the class of the image size name you specify in the functions.php file.

8
  • Hi Jeremy, many thanks for answering. I am still a bit unclear how this would be applied in the template. Would I just need to repeat the code three times for the three images as I have done above or would they be grouped together?
    – tobeeornot
    Commented Dec 1, 2011 at 15:20
  • You would just repeat the code, but change the, secondary-image to Quaternary to show that one and post-quaternary for the third. You could wrap them in a class if you are wanting to bunch them together, like this: <div class="multi-thumbs"><?php //your thumbnail code here...?></div> Commented Dec 1, 2011 at 16:29
  • I am really sorry but I am still having problems getting it to work. Would you mind looking at my template code to see if there is any mistakes? [pastebin.com/0Eg76GG3]
    – tobeeornot
    Commented Dec 1, 2011 at 16:44
  • I have edited the functions code above to reflect your code. I also want to add a class of .middle (padding settings) to each image but unsure where to apply the code.
    – tobeeornot
    Commented Dec 1, 2011 at 16:49
  • can't you use the current class that's output by the thumbs? Commented Dec 1, 2011 at 18:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.