Closed ghost closed 9 years ago
You'd need to use MultiPostThumbnails ::get_post_thumbnail_url()
not MultiPostThumbnails::get_post_thumbnail_id()
to get the URL of the thumbnail.
Still does not pull the image: `
MultiPostThumbnails::get_post_thumbnail_url() looks like it returns a string, you have to echo it...
so change
<section id="hero" class="major col-md-12" style="background: url(<?php if(class_exists('MultiPostThumbnails')) : MultiPostThumbnails::get_post_thumbnail_url('page','background-image'); endif; ?>)">
to:
<section id="hero" class="major col-md-12" style="background: url(<?php
if (class_exists('MultiPostThumbnails')) : esc_attr_e( MultiPostThumbnails::get_post_thumbnail_url('page','background-image') ); endif; ?>)">
I wrapped it in esc_attr_e for proper escpaping...
I didn't test this, but it should work... my formatting skills are not up to task, apologies.
This fixed the issue. Thank you for your help!
Hello, I would like to use this to display a background image on a page, not a post.
Heres the code i am using:
style="background: url(<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::get_post_thumbnail_id('page', 'background-image'); endif;
My function:if (class_exists('MultiPostThumbnails')) { new MultiPostThumbnails(array( 'label' => 'Background Image', 'id' => 'background-image', 'post_type' => 'page' ) ); }
However it does not display. When I use the regular "the_post_thumbnail" in the theme code, it will work correctly, but thats to generate the full image tag. Please let me know how to accomplish this on a page. Thanks.