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

Not outputting image correctly for 'Blog' page? #23

Closed guuthemes closed 10 years ago

guuthemes commented 10 years ago

Hey, great work, but having an issue with trying to show an image when a Blog page is set. It does not pull the featured image that has been set for the blog page, but more the image from the first post??

The code I have currently is -

<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail(get_post_type(), 'header-image', NULL, 'header-image-full'); endif; ?>

And then in header.php I have done (as I have slightly differing text) -

if is_page (works great)

else is_singular (works great)

else is_home (this is where the issue arises)

Any pointers dude?

Many thanks

chrisscott commented 10 years ago

You'll need to get the ID of the page you set as the front page or posts page in the Settings/Reading/Front page displays option. If you are using it on a page set as front page you'll need to pass get_option( 'page_on_front' ) as the third parameter to MultiPostThumbnails::the_post_thumbnail(). If you are using it on a page set as a posts page, you'd need to pass in get_option( 'posts_page' ) instead. If you need to cover both cases, use the is_home() and is_front_page() conditionals.

guuthemes commented 10 years ago

<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail(get_option('posts_page'), 'header-image', NULL, 'header-image-full'); endif; ?>

is returning no output?

banderon commented 10 years ago

get_option('posts_page') gets the post ID of the posts landing page. You want that as the third parameter in the function call; the first should still be the post type, which in this case would be 'page'.

guuthemes commented 10 years ago

<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail('page', 'header-image', 'posts_page', NULL, 'header-image-full'); endif; ?>

Am I missing something here?

banderon commented 10 years ago

<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::the_post_thumbnail('page', 'header-image', get_option('posts_page'), 'header-image-full'); endif; ?>

First parameter is the post type, third is the post ID (which you get from the option).

guuthemes commented 10 years ago

Doh!! Late night. Thanks. I'll try that.

guuthemes commented 10 years ago

Works. Only tweak I had to make is, it's page_for_posts, not posts_page.

thanks