Re: Sub-categories Tutorial

3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 18, 2013   (RSS)

By gregThomas - February 15, 2013

Hi Pete, 

To get this feature working you need to add in a liAttributesCallback to your getCategories function, here is some example code:

  //Get the category items
  list($mainNav, $selectedNav) = getCategories(array( 
    'tableName'            => 'menu_items', 
    'loadUploads'          => true,
    'liAttributesCallback' => 'liStyle'
  ));

  //If the category is selected, add a class of selected.
  function liStyle($category) {
    //Check if the user must be logged in to see the page.
    if ($category['num'] == $_REQUEST['category']) { return ' class="selected" '; }
    return '';
  }

This is just example code, so you'll need to change the variables to get it to work in your example. 

So the getCategories function has the liAttributesCallback item in it, this will look for a function called liStyle, and will add whatever is returned from it into the li tag. 

I've set up the function to check if the current category is selected in the URL, and if it is, it will return class="selected". Otherwise it will return nothing.

The class should be added to the _listItemStart field automatically when you display it. 

Let me know if you have any questions.

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By petejdg - February 18, 2013

Works brilliantly.... thank you so much!