WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] The body_class function (5 posts)

  1. HMW666
    Member
    Posted 3 years ago #

    Hi!

    I am pretty new to WP. I know xhtml & CSS though. At first it took me a while to get used to all the php codes and the whole structure of WP, now I think it's kind of fun, and a cool way to build websites.

    Anyway, coming from the world of ”classic” CSS/xhtml approach - I felt (and to some extent still do) ”locked in” by the templates. It's great that they are there, but they can also prove a bit difficult to modify.

    I just discovered (much to my delight) the body_class function, which allows me to set different backgrounds per page (amongst other things). I used the function to set a different background for a specifik div on a page, like so:

    .page-id-34 #wrapper
    {
    	 background-image: url('images/test.jpg');
    }

    It worked fine, which was great. So now I wanted to move on to some other pages with the exact same approach/picture, but it's (for some reason) a no-go. My little code-snippet looks like this:

    .page-id-34 #wrapper
    {
    	 background-image: url('images/test.jpg');
    }
    
    .page-id-37 #wrapper
    {
    	background-image: url('images/test.jpg');
    }

    To sum it up, it works for page 34, but not for page 37 - which strikes me as odd. If someone could point out where the error might be, I'd appreciate it.

    Thanks for reading this,

    HMW666

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    link to your site?

    have you cleared the browser cache?
    ('CTRL F5')

  3. HMW666
    Member
    Posted 3 years ago #

    Thank you for your reply. The site in question is for a friend of mine, I am not sure he want it to be ”public” at this point.

    Yes, I have cleared the cache, and tried it in both FF & Chromium - but still no cigar.

    The page that does not work is the ”blog” page, might that have something to do with it? The page where it works is a ”static” one.

    Thanks again!

    HMW666

  4. alchymyth
    Forum Moderator
    Posted 3 years ago #

    you can get the blog page with the css class .blog or
    body.blog

    (you are right, it does not output .page-id-77)

    (i quick look into the html code of the blog page in the browser could have shown you the body_classes)

  5. HMW666
    Member
    Posted 3 years ago #

    Right on dude!

    Thanks, you're right. For the life of me I don't know why I didn't check the source code for the body class, that's how I found the #wrapper div I was looking for in the first place!

    Thanks for your help alcymyth, I appreciate it!

    Best,

    HMW666

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags