Re: Sub-categories Tutorial
3 posts by 2 authors in: Forums > CMS Builder
Last Post: February 18, 2013 (RSS)
By petejdg - February 15, 2013
In response to: [url "http://www.interactivetools.com/forum/forum-posts.php?postNum=2201307#post2201307"]Sub-categories Tutorial[/url], ...
I am trying to get this to work with tinynav.js so I need to see if I can have it select and stay on the category in the drop down list. I see where you are adding in the <b>and </b> but I need my output to be <li class='selected'> instead of the <b> so it will highlight the category in the dropdown menu.
http://www.downtownsiouxcity.com/mobile/biz-directory-display.php?category=13
For example:
<ul id="nav">
<li class"selected"><a href="?category=1">Attractions</a></li>
<li><a href="?category=2">Shopping</a></li>
<li><a href="?category=4">Lodging</a></li>
<li><a href="?category=3">Dining</a></li>
</ul>
thanks,
pete
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
PHP Programmer - interactivetools.com