Hi. I am using a php include script to control my tabbed site navigation. I am using lists for my nav items.
I store the nav items in an array and use logic to tell the web page what the current nav item is by putting in either a <span> tag or <li class=”current”>, depending on the situation. I code each xhtml page with $thispage = x, so that the php script knows what the current page is.
Here is the navigation.php code that I came up with:
[code=php]
<?php
$navItem = array ( ‘first’=>’Home’,
‘second’=>’Photo Gallery’,
‘third’=>’Sandbox’,
‘fourth’=>’Aaron Resume’,
‘fifth’=>’Projects’,
‘sixth’=>’Writing’
);
?>
<ul id=”primary”>
<li>
<?php if ($thispage==”Home”) {
echo “<span>” . $navItem[first]. “</span>”; } else {
echo “<a href=’/index.php’>” . $navItem[first]. “</a>”; } ?>
</li>
<li>
<?php if ($thispageg==”gallery”){
echo “<a href=’/gallery’ class=’current’>” . $navItem[second] . “</a>”; } else {
echo “<a href=’gallery/index.php’>” . $navItem[second] . “</a>”; } ?>
</li>
<li>
<?php if ($thispage==”Sandbox”) {
echo “<span>” . $navItem[third] . “</span>”; } else {
echo “<a href=’/sandbox.php’>” . $navItem[third] . “</a>”; } ?>
</li>
<li>
<?php if ($thispage==”aaronResume”) {
echo “<span>” . $navItem[fourth] . “</span>”; } else {
echo “<a href=’/aaronResume.php’>” . $navItem[fourth] . “</a>”; } ?>
</li>
<li>
<?php if ($thispage==”projects”) {
echo “<span>” . $navItem[fifth] . “</span>”; } else {
echo “<a href=’/projects.php’>” . $navItem[fifth] . “</a>”; } ?>
</li>
<li>
<?php if ($thispage==”Writing”) {
echo “<span>” . $navItem[sixth] . “</span>”; } else {
echo “<a href=’/writing.php’>” . $navItem[sixth] . “</a>”; } ?>
</li>
</ul>
So, two questions:
1) Is there a more efficent way to code this so that in each if/else statemets I only have to reference the array element once?
2) If I want to use two levels of navigation, which I have already set up to do in my xHTML, would I want to use a 2 dimensional array? If so, can someone give me some hints on how to do this?