Get Parent Slug (4 posts)

  1. Danny159
    Posted 4 years ago #


    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.


  2. esmi
    Forum Moderator
    Posted 4 years ago #

  3. Danny159
    Posted 4 years ago #

    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. ]

  4. Danny159
    Posted 4 years ago #

    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));

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.