customizing menu on header.php for inner pages

I have a basic tab menu that is minimally customized depending on what page is viewed e.g. Page A is viewed so the Page A menu tab has a white background. All other tabs have a tan background. I’m trying to do this with a header.php, page.php, and a .css. So if the Title of the page.php is the same as one of the tabs then that tab should have a white background.

My code doesn’t work because I can’t push the $mainNav variable on the page.php back to the header.php. Not sure that’s even possible or maybe I’m just doing this a completely silly way. Little help. Thanks.

Header.php:

[php]<?php
$menu[0] = “A”;
$menu[1] = “B”;
$arrlength = count($menu);
?>

MY <?php echo $title; ?>

!!!
[/php]
Page.php:

[php]<?php
$title = “Home”;
$arrlength = count($menu);
include “header.php”;
?>

<?php for($x = 0; $x < $arrlength; $x++) { var_dump($title); var_dump($menu[$x]); if ($title == $menu[$x]){ $mainNav = "mainNav active"; echo "if " . $mainNav . $title . $menu[$x] ."

"; } else { $mainNav = "mainNav"; echo "else " . $mainNav . $title . $menu[$x] ."

"; } } ?> <?php include "footer.php"; ?>

[/php]

Well, there are many ways to pass data between pages. The simplest is to just include the data inside a
variable that can be passed on. This can be done with either posted form fields or in session variables.

I would suggest learning about session variables. These are attached to pages and saved on the server for
your use from page to page. Here is a quick explanation of how they work…

On every page you need to access the session, you must start it. This MUST be the first command on the page.
Therefore, you need to add this at the very top of each page:

<?PHP session_start(); ?>

This starts the session for that page. If the page is moved to another page on the site and if that second
page contains the above, then all variables you created in the session are still available for your uses. To
create a session variable, you simple create a variable like this:
$_SESSION[“variable_name”]=“variable_value”; Example: $_SESSION[“current_page”]=“A”;
In the second page if you need to find out what the current page is set to, you just read the variable and
use is as needed. Loosely like this:
$current_page = $_SESSION[“current_page”];
Or <?PHP echo $_SESSION["page_title"]; ?> Or whatever you would need to do with the
saved variable data…

You can destroy the session when done so the data is gone. Here is further info on this subject for you to
read that might show further insight into this.
http://www.w3schools.com/php/php_sessions.asp

Hope that helps!

Sponsor our Newsletter | Privacy Policy | Terms of Service