WordPress.org

Support

Support » Themes and Templates » [Resolved] TwentyEleven Mod – Using featured image in css

[Resolved] TwentyEleven Mod – Using featured image in css

Viewing 6 replies - 1 through 6 (of 6 total)
  • esmi
    Forum Moderator

    @esmi

    Are you saving the featured image url in a custom field called “thumb”.

    superpotion
    Member

    @superpotion

    I’m using the featured image feature within TwentyEleven, I’ll check the DB and see what it’s called there…

    superpotion
    Member

    @superpotion

    Thanks esmi, you got it – “thumb” doesn’t exist in postmeta table. (I lifted the code directly out of the get_post_meta() example in the codex – I won’t do that again!)

    Here’s the working solution:

    <?php
    if ( is_singular() && has_post_thumbnail( $post->ID )) :
       $thumb_id = get_post_meta($post->ID, '_thumbnail_id', true);
       $thumb_url = wp_get_attachment_url($thumb_id); ?>
    <style type="text/css">
    #primary { background: url("<?php echo $thumb_url ;?>") no-repeat scroll right bottom #FFFFFF; }
    </style>
    <?php endif;
    ?>
    Akhilesh Shivaraj
    Member

    @akkiblazeuts

    Hey superpotion,

    Do you add this code into the page.php file? Or the functions.php file? Sorry for the confusion.

    Thanks in advance,

    Blaze

    superpotion
    Member

    @superpotion

    @blaze – the code is in header.php of the child theme.

    Denis

    Akhilesh Shivaraj
    Member

    @akkiblazeuts

    @denis

    Thanks for clearing that up! 😀

    Blaze

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘[Resolved] TwentyEleven Mod – Using featured image in css’ is closed to new replies.