• I have a dynamic menu system based on listing categories and sub categories.

    Category tree like so…

    level 1 -product

    level 2 –bike
    level 3 —racing bikes, mountain bike etc..

    level 2 –accessories
    level 3 —helmet, clothing etc…

    at the top two levels i can show all child categorys like so:

    <?php wp_list_categories(‘orderby=name&child_of=’.$cat.’&title_li=&current_category=’.$myCat’); ?>

    but when i am displaying all the posts at the bottom level i need to be able to display the all the categories 1 level up form the current category.

    anyone help me here?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter dannybrowne

    (@dannybrowne)

    bump?!

    Thread Starter dannybrowne

    (@dannybrowne)

    got it…

    function:

    function get_parent_category_id($id, $level=0) {
    	$lookfor = "?cat=";
    	$endat = "\"";
    	$separator = "|";
    
    	$parent_list = get_category_parents($id, TRUE, $separator, FALSE);
    	$parents = explode($separator, $parent_list);
    	$parents[$level] = substr($parents[$level], strpos($parents[$level], $lookfor) + strlen($lookfor));
    	$parents[$level] = substr($parents[$level], 0, strpos($parents[$level], $endat));
    	return $parents[$level];
    }

    pass the category and depth you want to go into the above function.

    something like:

    <?php wp_list_categories(‘orderby=name&hide_empty=0&title_li=&parent=’.get_parent_category_id(get_query_var(‘cat’), 1)); ?>

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘need help with dynamic menu based on listing categories’ is closed to new replies.