views:

31

answers:

2

I have a menu, when the user clicks on any menu item, I want to take them to the same page, but I want to style the page differently depending on the menu item...for ex: change the background color to be different. What's the best way to do this? I was thinking that when they click on a menu item, a variable can be set or a session variable can be set.

Is there an easier way to do this? Does Wordpress have anything built into the architecture to make this easy?

A: 
  1. you have to create your page as a wp template ( if you did not created already ) ( see this )
  2. you are right with the session variable. pass the variable to that page and process it there. there is a bit of programming involved...

I do not know of another way for doing what you ask.

negatif
+2  A: 

Don't use the session for this. Since HTTP is a stateless protocol, you should avoid using session to the greatest lengths possible. Since the user is clicking on a link, it only makes sense making that link convey the information you're after. ust pass any data you want in the URL, e.g. as a a query string parameter;

Then you can just query for this in the page template like so:

<?php
  /*
  Template Name: Varying Background Color Template
  */

  $bgcolor = $_GET['bgcolor'];

  switch ($bgcolor) {
    case 1:
      // Change the background to color 1
      break;

    case 2:
      // Change the background to color 2
      break;

    case 3:
      // Change the background to color 3
      break;
  }
?>

If you think query string parameters are ugly, you can use path info instead, but this requires you to create a special case rewrite rule that makes the path info "invisible" to WordPress so it doesn't think it's the slug of a page. Whether you want or need this depends on how your permalink configuration in WordPress is.

asbjornu
I also found this after more searching and it uses a similar approach. http://wordpress.org/support/topic/get-variables-on-custom-admin-pages. It says that plugins that need to pass data between pages also use your GET method.
milesmeow