Where the key would be the cat_ID and the value would be either 0, if it has no children, or an array of it's children and so on. Does this make sense?
This example creates an unordered list, but you can change it to accommodate ordered lists, divs, drop down menus, whatever you fancy. I have just listed the categories but for a navigation you will obviously need to include hyperlinks.
Next a function that uses the walker to produce the navigation menu.
function category_navigation() { $walker = new CategoryNavigationWalker(); echo $walker->walk(get_categories(), 0); }
Finally, when you want to produce the navigation menu in your template use:
<ul><?php category_navigation(); ?></ul>
Hope that is easy to understand and solves your problem.
I need to make a custom nav bar based on categories.
For example:
Where the key would be the cat_ID and the value would be either 0, if it has no children, or an array of it's children and so on.
Does this make sense?
Thanks :D
Start by creating a class for your walker either in functions.php in your theme, or wherever you like. You can use this as a template.
class CategoryNavigationWalker extends Walker {
var $db_fields = array('parent' => 'parent', 'id' => 'term_id');
function start_lvl(&$output, $depth) {
$output .= \"<ul>\n\";
}
function end_lvl(&$output, $depth) {
$output .= \"</ul>\n\";
}
function start_el(&$output, $category, $depth, $args = null) {
$output .= \"<li>{$category->name}\";
}
function end_el(&$output, $category, $depth, $args = null) {
$output .= \"</li>\";
}
}
This example creates an unordered list, but you can change it to accommodate ordered lists, divs, drop down menus, whatever you fancy. I have just listed the categories but for a navigation you will obviously need to include hyperlinks.
Next a function that uses the walker to produce the navigation menu.
function category_navigation() {$walker = new CategoryNavigationWalker();
echo $walker->walk(get_categories(), 0);
}
Finally, when you want to produce the navigation menu in your template use:
Hope that is easy to understand and solves your problem.
Dave