Bootstrap nav-bar

3 posts by 2 authors in: Forums > CMS Builder
Last Post: August 3, 2014   (RSS)

By gregThomas - August 1, 2014

Hey Tim,

I implemented this exact system into another site the other day. Firstly, you'll need to set up a couple of call back functions that are used to inject the drop down menu classes into the appropriate UL and LI tags:


// load pages
list($categories, $selectedCategory) = getCategories(array(
  'tableName'            => 'categories',
  'ulAttributesCallback' => 'customMenuUlAttr', // ADVANCED: custom function to return ul attributes, eg: myUlAttr($category);
  'liAttributesCallback' => 'customMenuLiAttr', // ADVANCED: custom function to return li attributes, eg: myLiAttr($category);
));

function customMenuUlAttr($category) {
  return ($category['_hasParent'] && $category['depth'] == '1')? "class=\"dropdown-menu\" role=\"menu\"" : "" ;
}

function customMenuLiAttr($category) {
  return ($category['_hasChild'] && $category['depth'] == '0')? 'class="dropdown"': "" ;
}

So the customMenuUlAttr function checks if we're dealing with a second level item, and it has a parent. If both of these are true, it injects the drop down menu code.

The customMenuLiAttr function adds the class drop down to the top level li tag if it has children. 

After this it's just a case of making sure other items are added to the links that display when you loop thorugh the categories.  For example adding a dropdown-toggle class to a parent link, by checking the current category has a depth of zero, and has children in an if statement.

You can look at all of the meta fields that are included in a category section using the showme function:

showme($categoryRecord);

Adding the active class is a case of checking what the current select menu item is, and seeing if it matches the loop item. The current selected item is returned as the second item in the getCategories function. So using my above example I would use the following code:

<?php if ($category['num'] == $selectedCategory['num']:?>class="active"<?php endif; ?>

Let me know if you have any questions.

Cheers

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Toledoh - August 3, 2014

Great - thanks Greg!

Cheers,

Tim (toledoh.com.au)