Hi,
here is another method Dave showed me some time ago. I use this on all sites we create, works very good and is easy to adapt.
Remove your existing code in RED and replace with new code in BLUE in the list (load records) code. For the "customMenuUlAttr" and "customMenuLiAttr" I included more code than you need for your case just to some some examples. You need the one marked in BLUE.
// load records
list($pagesRecords, $pagesMetaData) = getCategories(array(
'tableName' => 'pages',
'defaultCategory' => '', // Enter 'first', a category number, or leave blank '' for none
'rootCategoryNum' => '0', // Only categories _below_ this one will be shown (defaults to 0 for all)
'categoryFormat' => 'showall', // showall, onelevel, twolevel, breadcrumb
'ulAttributes' => " class='dropdown' ", // add html attributes to <ul> tags
'ulAttributesCallback' => 'customMenuUlAttr', // ADVANCED: custom function to return ul attributes, eg: myUlAttr($category);
'liAttributesCallback' => 'customMenuLiAttr', // ADVANCED: custom function to return li attributes, eg: myLiAttr($category);
'ignoreHidden' => true, // don't hide records with hidden flag set
'useSeoUrls' => true,
));
// customMenuUlAttr
function customMenuUlAttr($category) {
$id = "id{$category['num']}";
$class = "depth{$category['depth']}";
return "class='$class'";
}
// customMenuLiAttr
function customMenuLiAttr($category) {
$id = "id{$category['num']}";
$class = "clickable depth{$category['depth']}";
if ($category['depth'] < 1) { $class .= " isTop"; }
if ($category['depth'] > 0) { $class .= " isChild"; }
if ($category['_isSelectedBranch']) { $class .= " isSelectedBranch"; }
if ($category['_isSelected']) { $class .= " isSelected"; }
if ($category['_isChildSelected']) { $class .= " childSelected"; }
if ($category['_hasChild']) { $class .= " hasChild"; }
return "class='$id $class'";
}
Now you can simply add if statements for any of these fields to add classes:
_isSelected
_isAncestorSelected
_isDescendantSelected
_isSelectedBranch
_isBreadcrumb
_hasParent
_hasChild
_isFirstChild
_isLastChild
_hasSiblings
_isSiblingSelected
_isParentSelected
_isChildSelected
-aev-