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:

  1. $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.
  2. For or foreach statement in PHP to loop through the navigation
  3. Optional: Variable declaration for subpage id & parent id ($sid and $pid)
  4. 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>&raquo;</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>&raquo;</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

  1. A "nav" classed div tag, use "class"; in case you'd like to include this in your footer as well
  2. This example uses an un-ordered list <ul>
  3. Simple PHP for statement. (more info)
  4. Declare $sid as subpage ID, using the array element $nav[$i] with value ['id']
  5. Declare $pid as the page parent ID, for use to retrieve sub-page navigation while on sub-pages
  6. Output a navigation item from the $nav[] element
  7. Attempt to retrieve subnavigation
  8. If there is subnavigation for the page
  9. Set up the subnavigation Item
  10. Simple PHP for statement
  11. Output a navigation item for the $snav[] element
  12. End for
  13. Close navigation container
  14. Else for the Conditional statement
  15. If the page is not a parent
  16. Attempt to pull the sub-page parent's sub-navigation
  17. Set up the subnavigation Item
  18. Simple PHP for statement
  19. Output a navigation item for the $snav[] element
  20. End for
  21. Close navigation container
  22. End nested if
  23. End if
  24. Clear $sid
  25. End parent navigation element in HTML
  26. End root for statement
  27. End </ul>
  28. 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.