WordPress.org

Ready to get started?Download WordPress

Forums

Highligh a element of my custom menu while browsing subcategories (2 posts)

  1. grosbouff
    Member
    Posted 6 years ago #

    Hello, I'm buidling a custom php-menu for my template; and one of my category menu is highlighting if we are in a specific category (a "root" category).

    <?php
    	}elseif (is_category('13')) { ?>
    		ShowMenu (3);
    	<?php
    	}

    But the problem is, that if we are browsing a child-category; this doesn't work anymore.

    So : how can I change my condition and build it to detect the parent category ? (not just 1 level up, because if I have sub-sub-categories, it will broke again)

    Thanks !

    I've read about
    <?php the_category('separator', 'parents' ); ?>
    but it must be in the loop so I can't use it.

  2. grosbouff
    Member
    Posted 6 years ago #

    I've found something, but it doesn't work if you click on a post... :(
    Any idea ?

    if (function_exists('bloginfo')) { //teste si on est dans le blog
    
    	$menu_categories = get_category_parents($cat, FALSE, '||', TRUE);
    	$menu_categories = explode("||", $menu_categories);
    	$menu_parent_cat = $menu_categories[0];	
    
    	if ( ($menu_parent_cat == 'anima') || (is_home()) ) {?>
    		ShowMenu (1);
    	<?php

Topic Closed

This topic has been closed to new replies.

About this Topic