WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Featured image as a full size background in div element (3 posts)

  1. hrrubin
    Member
    Posted 8 months ago #

    In the page.php I'm trying to add a div after the header. Inside this div I want the post's featured image as a full size background-image.

    I've been looking at various threads, but while some were resolved, I couldn't make it work.

    This and this.

    My webpage: http://rubinreklame.dk/design-til-folket/

    Below is some code, where I at least get something online (the alt-text).

    <div id="featuredimage">
    <?php
    $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); ?>
    <img src="<?php echo $url; ?>" longdesc="URL_2" alt="Text_2" />
    <?php ?>
    </div>
    #featuredimage{
    width:100%;
    height:600px;
    overflow:hidden;}
  2. alchymyth
    The Sweeper & Moderator
    Posted 8 months ago #

    the code seems to be working in my local test site.

    does that page have a featured image defined?

  3. hrrubin
    Member
    Posted 8 months ago #

    That was just the thing. I thought it was enough that some post had one, but I mixed the things up. It is, of course working just fine :)

    Thank you.

Reply

You must log in to post.

About this Topic