• Resolved chimovski

    (@chimovski)


    How do I set the secondary image as the background of an element? I’ve got my secondary image setup but can’t get the ‘get_post_thumbnail_url’ code to work. My code is this:

    <a class="thumbOverlay" style="background-image:url('<?php if (class_exists('MultiPostThumbnails')) : MultiPostThumbnails::get_post_thumbnail_url(get_post_type('MY-CPT'), 'secondary-image'); endif; ?>');" href="<?php echo the_permalink(); ?>"></a>

    The html is outputting thus:
    <a class="thumbOverlay" style="background-image: url(http://URL-OF-MY-PAGE/); " href="MY-PERMALINK"></a>

    http://wordpress.org/plugins/multiple-post-thumbnails/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter chimovski

    (@chimovski)

    OK I think my issue maybe because I wasn’t in the loop. But still not got it working. I have this now which displays the image fine as an img:

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

    But changing the the_post_thumbnail to get_post_thumbnail_url produces nothing. What am I doing wrong?

    Thread Starter chimovski

    (@chimovski)

    Got it working: cpt of suites and secondary image of rollover-image. Used a variable and did the trick.

    <?php $secondary_image_url = MultiPostThumbnails::get_post_thumbnail_url('suites','rollover-image'); ?>
    
             <a class="thumbOverlay" style="background-image:url('<?php echo $secondary_image_url ?>');" href="<?php echo the_permalink(); ?>"></a>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Setting secondary image as element background’ is closed to new replies.