admin管理员组

文章数量:1026655

I made a Navigation (primary) via Appearance->Menus which navigates the user to anchor tags on the side, but I also have subpages, where I want a different navigation - only with my 'Home'-button in it. Which would mean I need to get rid of the other navigation points.
I did create another sub-navigation for the subpages, but don't know how to get it up.

My header.php shows me
<php if (has_nav_menu ( 'primary') ) : ?>
Can i just do an else with another navigation?

My Theme only supports one menu though ...

Big thanks for the help! :)

I made a Navigation (primary) via Appearance->Menus which navigates the user to anchor tags on the side, but I also have subpages, where I want a different navigation - only with my 'Home'-button in it. Which would mean I need to get rid of the other navigation points.
I did create another sub-navigation for the subpages, but don't know how to get it up.

My header.php shows me
<php if (has_nav_menu ( 'primary') ) : ?>
Can i just do an else with another navigation?

My Theme only supports one menu though ...

Big thanks for the help! :)

Share Improve this question edited Mar 28, 2019 at 20:46 Kalex asked Mar 28, 2019 at 16:48 KalexKalex 135 bronze badges 7
  • Welcome to site :) May you please clarify your question by explaining how your theme is currently laid out? For example, is your primary navigation in header.php or elsewhere...? Also, the different navigation you referred to: how different is it? (1) entirely different, or (2) adds a one or two links to the original nav, or (3) removes one or two links...? The more information you can provide the better (and faster) answers you will get from the community here. And don't worry about being a beginner: everyone here was once a beginner. – jsmod Commented Mar 28, 2019 at 17:12
  • PS. You can edit your question to add the details there instead of responding to this comment, that way the information will be more visible to readers. – jsmod Commented Mar 28, 2019 at 17:15
  • 1 Thanks for the help on the edit, @jsmod! And thanks for the nice words~ – Kalex Commented Mar 28, 2019 at 17:33
  • Glad to assist :) Please bear with me as I ask more questions: I noticed you mentioned your theme supports one menu, yet you created a sub-navigation for your other pages. Do you mean you hard coded that sub-navigation menu in your header.php file? If yes, you might want to consider creating a child theme before you continue because any changes you make to the original (parent) theme will be gone when that theme is updated. A child theme will preserve the changes you make. – jsmod Commented Mar 29, 2019 at 20:30
  • A quick an easy way to get a link for Home on all pages and your primary menu on only the index/home page is suggested in an answer below by Monkey Puzzle. If that works for you, please mark it as answered so others searching for the same thing can easily see the solution. – jsmod Commented Mar 29, 2019 at 20:31
 |  Show 2 more comments

2 Answers 2

Reset to default 0

It doesn't sound like you need another Navigation menu.

How about something like this:

<?php if ( is_page() && $post->post_parent > 0 ) { 
   // we know we are on a sub/child page now...
   // PS. another way to handle this would be to check if you were on a particular page template or particular page ids etc.
?>
<a class="awesome-button" href="<?php echo esc_url( home_url( '/' ) ); ?>">Go home!</a>
<?php 
    // just show a link Home for the subpages...
} else {
   // now we are NOT on a subpage, so show the Primary nav menu...
   wp_nav_menu( array('menu' => 'primary') );
} ?>

Hi @Kalex you can use the get_header for your custom header.php file. You can get the example code from here: https://developer.wordpress/reference/functions/get_header/ .

The combination of Template Name with Custom Header is very make sense for this case (if I understand right your question).

I made a Navigation (primary) via Appearance->Menus which navigates the user to anchor tags on the side, but I also have subpages, where I want a different navigation - only with my 'Home'-button in it. Which would mean I need to get rid of the other navigation points.
I did create another sub-navigation for the subpages, but don't know how to get it up.

My header.php shows me
<php if (has_nav_menu ( 'primary') ) : ?>
Can i just do an else with another navigation?

My Theme only supports one menu though ...

Big thanks for the help! :)

I made a Navigation (primary) via Appearance->Menus which navigates the user to anchor tags on the side, but I also have subpages, where I want a different navigation - only with my 'Home'-button in it. Which would mean I need to get rid of the other navigation points.
I did create another sub-navigation for the subpages, but don't know how to get it up.

My header.php shows me
<php if (has_nav_menu ( 'primary') ) : ?>
Can i just do an else with another navigation?

My Theme only supports one menu though ...

Big thanks for the help! :)

Share Improve this question edited Mar 28, 2019 at 20:46 Kalex asked Mar 28, 2019 at 16:48 KalexKalex 135 bronze badges 7
  • Welcome to site :) May you please clarify your question by explaining how your theme is currently laid out? For example, is your primary navigation in header.php or elsewhere...? Also, the different navigation you referred to: how different is it? (1) entirely different, or (2) adds a one or two links to the original nav, or (3) removes one or two links...? The more information you can provide the better (and faster) answers you will get from the community here. And don't worry about being a beginner: everyone here was once a beginner. – jsmod Commented Mar 28, 2019 at 17:12
  • PS. You can edit your question to add the details there instead of responding to this comment, that way the information will be more visible to readers. – jsmod Commented Mar 28, 2019 at 17:15
  • 1 Thanks for the help on the edit, @jsmod! And thanks for the nice words~ – Kalex Commented Mar 28, 2019 at 17:33
  • Glad to assist :) Please bear with me as I ask more questions: I noticed you mentioned your theme supports one menu, yet you created a sub-navigation for your other pages. Do you mean you hard coded that sub-navigation menu in your header.php file? If yes, you might want to consider creating a child theme before you continue because any changes you make to the original (parent) theme will be gone when that theme is updated. A child theme will preserve the changes you make. – jsmod Commented Mar 29, 2019 at 20:30
  • A quick an easy way to get a link for Home on all pages and your primary menu on only the index/home page is suggested in an answer below by Monkey Puzzle. If that works for you, please mark it as answered so others searching for the same thing can easily see the solution. – jsmod Commented Mar 29, 2019 at 20:31
 |  Show 2 more comments

2 Answers 2

Reset to default 0

It doesn't sound like you need another Navigation menu.

How about something like this:

<?php if ( is_page() && $post->post_parent > 0 ) { 
   // we know we are on a sub/child page now...
   // PS. another way to handle this would be to check if you were on a particular page template or particular page ids etc.
?>
<a class="awesome-button" href="<?php echo esc_url( home_url( '/' ) ); ?>">Go home!</a>
<?php 
    // just show a link Home for the subpages...
} else {
   // now we are NOT on a subpage, so show the Primary nav menu...
   wp_nav_menu( array('menu' => 'primary') );
} ?>

Hi @Kalex you can use the get_header for your custom header.php file. You can get the example code from here: https://developer.wordpress/reference/functions/get_header/ .

The combination of Template Name with Custom Header is very make sense for this case (if I understand right your question).

本文标签: menusHow to have the Header show different content on different pages