WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Different backgroundcolors for different pages (3 posts)

  1. jpdeboer
    Member
    Posted 3 years ago #

    I read the topic "[resolved] Different background color on each page".
    It says:

    By "page," I assume you are using that in the WP-Admin sense of the word. In that case, go into the template's page.php (if there is one). If you see a <body> tag near the top, that's our destination. Depending on the theme author, <body> might actually be in header.php

    Then replace the body tag with something like this:

    <?php if (is_page()){ ?>
       <body class="page-<?php the_ID(); ?>">
    <?php }else{
       <body>
    <?php } ?>

    That's for if the body tag was in header.php. If it's in page.php, you wouldn't need all the conditions.

    Then, just go into your style sheet and add a single line for each page, like this:

    body.page-1{background:#fff;}
    body.page-2{background:#f00;}

    etc. You'll find the page ID's on the "Manage Posts" screen.

    (You might actually need to write something like "body.page-1 container{}" if that's how your CSS is set up.)

    Now what I have in header.php is
    <body id='top' <?php body_class($k_body_class);?> >
    How do I combine this body-tag with the suggested change?

    Anyone have a solution?
    Thanks in advance!!

  2. alchymyth
    The Sweeper & Moderator
    Posted 3 years ago #

    How do I combine this body-tag with the suggested change?

    if that code follows the general direction of the wordpress body_class() function, probably not at all - look into the html code of your different pages, to see the different css classes of the body tag - there will probably be an individual class, such as .page-id-23 for a page (among other classes).

    if you need someone to have a look, please post a link to your site.

  3. jpdeboer
    Member
    Posted 3 years ago #

    Found the way, thanks to your reply alchymyth!
    Thanks for giving me the right direction!!

Topic Closed

This topic has been closed to new replies.

About this Topic