I am building a site using a custom WP theme, and I have been using:
<?php include('header-bar.php'); ?>
in order to include a navigation bar on each page. I intentionally didn't put the navigation in the header.php file because I don't need it on every page.
That bit of code is working fine in certain places, but failing in others.
It works in this scenario:
<?php get_header(); ?>
<div class='main-content'>
<?php include('header-bar.php'); ?>
<div class='container'>
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile; endif;
?>
</div>
</div>
<?php get_footer(); ?>
but it mysteriously fails in this scenario:
<?php
/*
Template Name: Contact
*/
?>
<?php get_header(); ?>
<div class='main-content'>
<?php include('header-bar.php'); ?>
<div class='container'>
<?php
if ( have_posts() ) : while ( have_posts() ) : the_post();
get_template_part( 'content', get_post_format() );
endwhile; endif;
?>
</div>
</div>
<?php get_footer(); ?>
In this second scenario, the page displays properly, except for a the 'header-bar.php' code which is nowhere to be found. The change that I am making that seemingly 'breaks' this line of code is by adding the template name. Can anyone offer some insight into why this may be? I'm baffled.
Thanks in advance! CPR