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.


Viewing 3 replies - 1 through 3 (of 3 total)
  • 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));
        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:

    $parentslug = explode("/", $_SERVER['REQUEST_URI']);
    if($parentslug[1] == "parent1"){
    	$theNav = "nav5";
    if($parentslug[1] == "parent2"){
    	$theNav = "nav4";
    if($parentslug[1] == "parent3"){
    	$theNav = "nav3";
    if($parentslug[1] == "parent4"){
    	$theNav = "nav2";
    	$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.