FAQ - Menu Builder Function

Menu Builder Function

19.11.2015 3631


In case you building a new template for CMS this is how you use the new menu builder invented in CMS 1.4.

All modern menus are based on lists, classes and sub classes. With CMS 1.4 it is super easy to use the automatic menu builder.

With one line of code your menu, sub menu, sub sub menu and so on up to five levels will be build automatically.

<?php echo jak_build_menu(0, $mheader, $page, 'nav nav-main navbar-nav navbar-right', 'dropdown', 'dropdown-menu', 'dropdown-submenu', false);?>

Let's pull apart the function.

  • 0 = root
  • $mheader = Header Menu / $mfooter = Footer Menu
  • $page = The page we are on for the active class, so we can mark the menu we are currently on
  • nav nav-main navbar-nav navbar-right = the main class for the menu
  • dropdown = To mark the list that there is a dropdown
  • dropdown-menu = the sub menu class for the first list
  • dropdown-submenu = the sub menu class for the sub menu
  • false = should we show the admin link (when logged in and have access)

This will produce a menu like this:

<ul class="nav nav-main navbar-nav navbar-right">
<li><a href="/">Home</a></li>
<li class="dropdown"><a href="/software">Software</a>
<ul class="dropdown-menu">
<li class="dropdown-submenu"><a href="/live-chat">Live Chat</a>
<ul class="dropdown-menu">
<li><a href="/compare">Compare</a></li>
<li><a href="/lc-websocket">WebSocket</a></li>
<li><a href="/lc-business">Business</a></li>
<li><a href="/lc-wordpress">WordPress</a></li>
<li><a href="/lc-light">Light</a></li>
</ul>
</li>
<li><a href="/cms">CMS</a></li>
<li><a href="/helpdesk">HelpDesk</a></li>
<li><a href="/dragdrop-shop">DragDrop Shop</a></li>
<li><a href="/feedback">Feedback</a></li>
</ul>
</li>
<li><a href="/pricing">Pricing</a></li>
<li><a href="/shop">Shop</a></li>
<li><a href="/demos">Demos</a></li>
<li><a href="/download">Download</a></li>
<li><a href="/blog">Blog</a></li>
<li><a href="/faq">FAQ</a></li>
<li><a href="/support">Support</a></li>
<li><a href="/hosting">Hosting</a></li>
<li><a href="/contact">Contact</a></li>
</ul>

Now it is just a mater of having the right classes to build the menu.