Navigation based on the page used
page-yourcustomnamehere.php
.page.php
or index.php
and change it to what you need.nav.php
nav-yourcustomnamehere.php
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.
<nav>
<?php
/*
* 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 );
?>
</nav>