Support » Fixing WordPress » Get Parent Slug

  • Hey,

    I am making a theme, and I want to include different menu’s depending on the parent slug…

    For example if the user is on a page like

    /cat1/my-page/ -> It will show menu 1
    /cat2/my-page/ -> Will show the menu for cat2?

    I can find any function to allow this?
    Does anyone know how I can fix this problem.

    Dan

Viewing 3 replies - 1 through 3 (of 3 total)
  • esmi

    (@esmi)

    Forum Moderator

    That doesnt seem to show me the slug?

    What I want to do is in my template I want to do an if statement… eg…

    if($parent_slug == "cat1"){
        wp_nav_menu(array('theme_location' => 'main', 'menu_class' => 'simple-nav', 'container' => false));
    }else{
        wp_nav_menu(array('theme_location' => 'cat2', 'menu_class' => 'simple-nav', 'container' => false));
    }

    [ Please do not bump, it’s not permitted here. ]

    Ok I sorted this, I didnt think you could run any php in a template file but you can… so here is how I fixed it just incase anyone wants to know:

    <?php
    $parentslug = explode("/", $_SERVER['REQUEST_URI']);
    if($parentslug[1] == "parent1"){
    	$theNav = "nav5";
    }else
    if($parentslug[1] == "parent2"){
    	$theNav = "nav4";
    }else
    if($parentslug[1] == "parent3"){
    	$theNav = "nav3";
    }else
    if($parentslug[1] == "parent4"){
    	$theNav = "nav2";
    }else{
    	$theNav = "aboutnav";
    }
    
    wp_nav_menu(array('theme_location' => $theNav, 'items_wrap' => '<ul>%3$s</ul>', 'container' => false));
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Get Parent Slug’ is closed to new replies.