Closed NielsTieman closed 9 years ago
If you just use get_post_thumbnail_id()
you'll only be getting the default thumbnail.
To get the secondary, you should be using https://github.com/voceconnect/multi-post-thumbnails/wiki/Functions-and-Template-Tags#get_post_thumbnail_url and the id parameter should be whatever you named the secondary image. So if you just used the example code to register that image like here, https://github.com/voceconnect/multi-post-thumbnails/wiki#register-a-new-thumbnail, then it would be secondary-image
.
<?php
$src = MultiPostThumbnails::get_post_thumbnail_url( get_post_type( $post->ID ), 'secondary-image', $post->ID, 'thumbnails' );
?>
<div class="background" style="background-image: url('<?php echo $src; ?>')"></div>
But you should also add a check in there to ensure that $src
is not false before trying to set it as the background image as well as run esc_url()
on the value.
Kevin,
Thank you so much. This works like a charm. I wil look into the $src and the esc_url().
Hi,
First of all; thanks for the plugin!
I got everything working with one featured image. Now I added the the plugin for a second one and then the problems start. But I can't seem to figure out how to change my code to look at the secondary-image.
I can't seem to figure out what to change in my code to get this working, and it has been hours. So, thanks in advance for the tips and hopefully a solution.