3/7/2014 - 7:21 PM

Navigation based on the page used

Navigation based on the page used

  • Create a new PHP file named page-yourcustomnamehere.php.
  • Add /* Template Name: Your Custom Name */ in the top. This name is what you look for in the editor.
  • Add your code (feel free to copy from page.php or index.php and change it to what you need.
  • Create your nav menu and add it to nav.php
  • Create a custom menu and add it to nav-yourcustomnamehere.php
  • Add the code in custom-nav-caller.php example file to where you want your nav to go inside page-yourcustomnamehere.php.

The code looks for a file named nav-{$whatever}.php, where $whatever is the slug of your file. If it exists, it'll include that file. If not, it falls back to nav.php, so it's important that that file exists.

 * Loads up the appropriate nav menu dynamically
 * based on what type of page/post we're using.
if ( is_page_template() ) {
    $slug = str_replace( '.php', '', get_page_template_slug() );
} else {
    $slug = get_post_type();

get_template_part( 'nav', $slug );