WordPress.org

Ready to get started?Download WordPress

Forums

featured image as site background (3 posts)

  1. VanNotenAlec
    Member
    Posted 1 year ago #

    Hi guys,

    So I'm making a theme for a deejay and i want to display the featured img (the big version) as background when it's set into the post/page

    I already activated the function in functions.php

    BUT! when there's no featured image (in archive etc) selected, it has to take a random iamge out of a directory in the theme folder.

    <body <?php body_class(); ?>>
    
    <!-- SET BACKGROUND -->
    <div id="maximage">
    	<?php if ( has_post_thumbnail() ) {
    	the_post_thumbnail(); } else ?>
    	<img src="<?php echo get_template_directory_uri(); ?>/img/fp/sakso003.jpg" alt="" />
        <?php endif ?>
    </div> <!-- #maximage -->
    
    <div class="gridContainer clearfix" class="hfeed site">

    this is done in header.php so it's outside the loop.

    thanks in advance!

    (the background is using the Maximage v2 Javascript/background-slider)

  2. Andrew
    Forum Moderator
    Posted 1 year ago #

    I could try help out with the CSS-side of it if you want, but you'll need to provide a link to your webpage with the featured image already.

  3. VanNotenAlec
    Member
    Posted 1 year ago #

    the css and stuff is all done. it's the php I need ;-)

    the javacript turns the div with id="maximage" into a background us lower z-index etc. So that's all ok!

    inside the div i've put
    <img src="<?php echo get_template_directory_uri(); ?>/img/fp/sakso003.jpg" alt="" />
    for now.

Topic Closed

This topic has been closed to new replies.

About this Topic