WordPress.org

Support

Support » Themes and Templates » Different codes for main page and single posts

Different codes for main page and single posts

  • Hello!

    Is there a css / php code that makes possible showing a background image on the main page of my blog and another different background on single pages?

    I’ve heard it’s possible and it’s not difficult.

Viewing 1 replies (of 1 total)
  • esmi

    @esmi

    Forum Moderator

    Something like:

    <?php if( is_home() || is_front_page() ) $backround_image = 'image1.jpg';
    else $backround_image = 'image2.jpg';
    $bg = get_bloginfo('template_directory'); ?>
    ?>
    <style type = "text/css">
    body{background-image:url(<?php echo get_bloginfo('stylesheet_directory') .' /images/' . $backround_image;?>}
    </style>

    in the <head></head> section of your theme’s header.php template file should work. It assumes that the two images will be present in your theme’s images folder.

Viewing 1 replies (of 1 total)
  • The topic ‘Different codes for main page and single posts’ is closed to new replies.
Skip to toolbar