I am using php include to include a header and footer on my web pages. I have a navbar on all the headers and wanted to know if there is a way to have the header.phph not show up some of the nav items on certain pages. For example , people dont need to navigate to the contact page from the contact page so this nav item is not required. Hope someone can assist.
Index.php
<?php
include('header.php');
?>
<div class="third_bar">
<div class="second_image">
</div>
<div class="form">
<form action= "search.php" method="post">
<input type="text" id="search_bar" placeholder="" value="Search" max length="30" autocomplete="off" onMouseDown="active();" onBlur="inactive();"/><input type="submit" id="search_button" value="Go!"/>
</form>
</div>
</div>
<?php
include ('footer.php');
?>
Header.php
!doctype html>
<html>
<head>
<meta charset="utf8">
<link rel="icon" href="http://www.com/favicon.png?v=2"/>
<title>Wcom</title>
<link rel= "stylesheet" href="style5.css"/>
</head>
<script type="text/javascript">
function active() {
var search_bar= document.getElementById('search_bar');
if(search_bar.value == 'Search here') {
search_bar.value=''
search_bar.placeholder= 'Search here'
}
}
function inactive() {
var search_bar= document.getElementById('search_bar');
if(search_bar.value == '') {
search_bar.value='Search here'
search_bar.placeholder= ''
}
}
</script>
<div id="container">
<div class="top_section">
<div class="first_image">
<a href="#"><img src="logo.png"/></a>
</div>
</div>
<div class="nav_bar">
<a href ="#"> About us</a>
<a href ="#"> Products & Pricing</a>
<a href ="contactpage.php"> Contact us</a>
<a href ="#"> login</a>
</div>
<!doctype html>
<html>
<head>
<meta charset="utf8">
<link rel="icon" href="http://"/>
<title>?.com</title>
<link rel= "stylesheet" href="style5.css"/>
</head>
<script type="text/javascript">
function active() {
var search_bar= document.getElementById('search_bar');
if(search_bar.value == 'Search here') {
search_bar.value=''
search_bar.placeholder= 'Search here'
}
}
function inactive() {
var search_bar= document.getElementById('search_bar');
if(search_bar.value == '') {
search_bar.value='Search here'
search_bar.placeholder= ''
}
}
</script>
<div id="container">
<div class="top_section">
<div class="first_image">
<a href="#"><img src="logo.png"/></a>
</div>
</div>
<div class="nav_bar">
<a href ="#"> About us</a>
<a href ="#"> Products & Pricing</a>
<a href ="contactpage.php"> Contact us</a>
<a href ="#"> login</a>
</div>
One simple way to do this is to add conditional on your header.php page.
Say you have a variable at the beginning of each page which contains the page name, for instance on "contactpage.php":
$page = 'contact';
(note there is also a way to get the name of the current page on the $_SERVER
superglobal variable)
Then you can conditionnally print your links in the navbar:
<div class="nav_bar">
<a href ="#"> About us</a>
<a href ="#"> Products & Pricing</a>
<?php if ($page !== 'contact') { ?>
<a href ="contactpage.php"> Contact us</a>
<?php } ?>
<a href ="#"> login</a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.