Building Navigation
Instead of having functions for creating the navigation for you, Projexr allows you to manually create and formulate your navigation however you'd like. Images, ordered or un-ordered lists, heading tags, paragraphs, whatever you'd like to use can be leveraged to create your navigation by following the instructions below:
- $nav = getNav(0) - Include this line at the start of your navigation, or at least before you wish to start filing through your navigation. getNav(0) is a function that passes "root" (or level-0) to the getNav function located in px-engine. This returns the root pages of the site that aren't marked "hidden" from the navigation.
- For or foreach statement in PHP to loop through the navigation
- Optional: Variable declaration for subpage id & parent id ($sid and $pid)
- Echo your HTML objects
I've included a sample nav.php file below.
<div class="nav">
<ul>
<? for($i=0; $i<count($nav); $i++) {
$sid = $nav[$i]['id'];
$pid= $nav[$i]['parent'];
echo '<li><a href="'.SITE_URL.$nav[$i]['pagename'].'/">'.$nav[$i]['title'].'</a>';
$snav=getNav($sid);
if($snav) {
echo "<div id='subnav'><ul class='subnav'><li>»</li>";
for($n=0; $n<count($snav);$n++) {
echo '<li><a href="'.SITE_URL.$nav[$i]['pagename']."/".$snav[$n]['pagename'].'/">'.$snav[$n]['title'].'</a></li>';
}
echo "</ul></div>";
} else {
$snav=getNav($pid);
if($snav) {
echo "<div id='subnav'><ul class='subnav'><li>»</li>";
for($n=0; $n<count($snav);$n++) {
echo '<li><a href="'.SITE_URL.$nav[$i]['pagename']."/".$snav[$n]['pagename'].'/">'.$snav[$n]['title'].'</a></li>';
}
echo "</ul></div>";
}
}
}
$sid=NULL;
echo "</li>";
}
?>
</ul>
</div>
Line by line definition of the above
- A "nav" classed div tag, use "class"; in case you'd like to include this in your footer as well
- This example uses an un-ordered list <ul>
- Simple PHP for statement. (more info)
- Declare $sid as subpage ID, using the array element $nav[$i] with value ['id']
- Declare $pid as the page parent ID, for use to retrieve sub-page navigation while on sub-pages
- Output a navigation item from the $nav[] element
- Attempt to retrieve subnavigation
- If there is subnavigation for the page
- Set up the subnavigation Item
- Simple PHP for statement
- Output a navigation item for the $snav[] element
- End for
- Close navigation container
- Else for the Conditional statement
- If the page is not a parent
- Attempt to pull the sub-page parent's sub-navigation
- Set up the subnavigation Item
- Simple PHP for statement
- Output a navigation item for the $snav[] element
- End for
- Close navigation container
- End nested if
- End if
- Clear $sid
- End parent navigation element in HTML
- End root for statement
- End </ul>
- End </div>
The source of the above file can be downloaded here. This is the exact file that is used in the "projexr" theme for this site.