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?
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