1

I am using built-in Wordpress function to add (small) thumbnails to each post. In addition to the post thumbnail I am using MultiPostThumbnail plugin to add custom category (large) image.

Since not all posts have thumbnails or "secondary image" (as it is called by MultiPostThumbnail plugin) I would like to display thumbnails (either large or small) in this order:

  1. If I a post has large (MultiPostThumbnails) thumbnail and (small) thumbnail display only (large) thumbnail.

  2. If a post doesn't have a (large) thumbnail display the (small) thumbnail.

I hope now it makes more sense. It's a simple if statement but I can't get it to work. Here is a "pseudo-code".

<?php if (class_exists('MultiPostThumbnails')
   && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) :
      MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image', NULL,  'post-secondary-image-thumbnail');
else {
   the_post_thumbnail();
}
?>
3
  • It's not clear what your question is. Does the code you provided not work? Did you write this yourself or did you find it somewhere?
    – Jan Fabry
    Commented Jan 3, 2011 at 12:31
  • I added a better description of my problem. The code above is a 'pseudo code'. It doesn't work.
    – eeyore
    Commented Jan 3, 2011 at 15:24
  • For me this looks like you're looking for a specific feature of that plugin. Please contact the plugin author and discuss your needs with her/him.
    – hakre
    Commented Jan 4, 2011 at 18:23

1 Answer 1

3

In code you posted you have issue with syntax - you should stick either with braces style or colons style, mixing them is not supported.

if(class_exists('MultiPostThumbnails')
    && MultiPostThumbnails::has_post_thumbnail('post', 'secondary-image')) {

    MultiPostThumbnails::the_post_thumbnail('post', 'secondary-image', NULL, 'post-secondary-image-thumbnail');
} 
else {

    the_post_thumbnail();
}

Your Answer

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