Support » Fixing WordPress » Forcing use of category's parent vars

  • I’ve been carefully using category-specific info for powering a dynamic header.php but I’ve come to a problem that I’m not sure how to solve.

    Each of 4 header buttons links to a separate category. Fine. Below this I’m displaying a contextual “submenu”–a mix of various posts, pages and (sub)categories.

    The problem arises when one of the submenu items contains a link to a (sub)category (a category under a parent category). I start getting references only to the (sub)category, as if WP has forgotten all about the (presumably overriding) parent category. This is a real problem.

    The code I run just before I build the contextual menu is:

    if (is_category()) {
    $cat = get_the_category();
    $cat = $cat[0];
    $catSlug = $cat->slug;
    	if (is_category('3')) {
    	//Start building this section 3 contextual menu
    	$thisCategory = $cat->cat_name;

    I started jumping through hoops trying to force WP to refer only to the parent category in any circumstance, but it either doesn’t work or has unpredictable output.

    How does one specify that, even if the content I’m looking at from the current subcategory (a list of posts, for example), WP should only look at the parent category’s vars?

    Very stumped on this one. Any advice would be hugely appreciated.

  • The topic ‘Forcing use of category's parent vars’ is closed to new replies.