voceconnect / multi-post-thumbnails

Adds multiple post thumbnails to a post type. If you've ever wanted more than one Featured Image on a post, this plugin is for you.
143 stars 63 forks source link

Help adding custom image size #98

Closed dsgnr closed 8 years ago

dsgnr commented 8 years ago

Hello,

Not an issue presé. I am trying to add a custom image size to the new loop and can't seem to get the new size to show... it's still just showing the full size image.

Here is what I am trying on my template page: <?php MultiPostThumbnails::the_post_thumbnail( get_post_type(), 'first-portrait-image'), size('portrait-image'); ?>

In this case, the image size is simply 'portrait-image'.

I have looked on the wiki but can't seem to suss it out.

Thank you in advance!

chrisscott commented 8 years ago

Here's the info on using that function. The size parameter is the 4th one and needs to be an array. So you probably need to use something like:

<?php 
MultiPostThumbnails::the_post_thumbnail(
  get_post_type(),
  'first-portrait-image',
  null,
  'portrait-image' 
);
?>

updated to correct last argument based on comment below from @lunule in case anyone doesn't read that far

dsgnr commented 8 years ago

Thank you for your quick response… I have put your code in but although is shows an image (the incorrect one, one that isn't even specified in my functions.php file, I also get a media.php error. Here is what I have currently:

Functions.php: new MultiPostThumbnails( array( 'label' => 'First Portrait Image', 'id' => 'first-portrait-image', 'post_type' => 'post' ) );

Index.php: <?php MultiPostThumbnails::the_post_thumbnail( get_post_type(), 'first-portrait-image', null, array('portrait-image' ) ); ?>

The image that appears is 150px square, whereas the actual image I am trying to call is 355x533. The error I get on the front end is: Notice: Undefined offset:

I am sure I am doing something wrong as it's showing a thumbnail that isn't specified anywhere, even in the media section of settings. Everything else I have tried, simply shows the full size image but with no error message.

Thanks!

chrisscott commented 8 years ago

It looks like your thumbnail registration is incorrect. See the docs for instantiating the class and an example.

lunule commented 8 years ago

If anyone's still confused a little bit: Chris' original code is almost OK. But instead of array -which didn't work for me either- use the single, quoted format name.

Didn't work: array( 'portrait-image' ) Works fine: 'portrait-image'

So the final display code in this case looks like:

<?php 
MultiPostThumbnails::the_post_thumbnail(
  get_post_type(),
  'first-portrait-image',
  null,
  'portrait-image'
);
?>