Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have different menu items. When the user clicks on a menu item, I want them to go to a particular destination. Each menu's destination has a different background color.

I'm thinking that I can pass a variable around and based on the value, I can set the bgcolor.
This is just one example of why I want to pass data around.

Does Wordpress have anything built in that allows me to do this? Should I use session variables?

share|improve this question

2 Answers 2

up vote 2 down vote accepted
I have different menu items. When the user clicks on a menu item, I want them to go to a particular destination. Each menu's destination has a different background color.

When you say destination I assume you mean page or post. If you use WordPress's built in body class and post class you can target the page or post in your CSS and assign a different background color for each.

How to use WordPress body class:

In header.php add body_class() between the body tags and WordPress will assign a different class to each page. The body tag:

<body <?php body_class(); ?>>

This will output your body tag in html like so:

<body class="page page-id-11 page-template page-template-default">

To assign the background color in css:

body.page-id-11 {
background:#000000;
}

Then you would just repeat the above for each page that needs a different background color.

How to use WordPress post class:

In your template file that is displaying the post, single.php or index.php add the following in the loop:

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

This will output your html like so:

<div id="post-47" class="post-47 post type-post hentry category-your-category tag-your-tags">

Use CSS to target the post just like we did the body using any of the outputted class or ids

share|improve this answer
    
Thanks Chris_O. That's a great answer and also allows me to do other visual customizations! –  milesmeow Aug 29 '10 at 1:55

WordPress doesn't use session variables ... so you might run into problems if you try that approach. From your description, though, I'd suggest adding a variable via the URL's query string. You can use WordPress permalinks system to do this, or merely add "?bg=123" to the end of the URL. Then use that variable to determine which background color to use.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.