[英]PHP Include , but only certain things
I am using php include to include a header and footer on my web pages.我正在使用 php include 在我的网页上包含页眉和页脚。 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.
我在所有标题上都有一个导航栏,想知道是否有办法让 header.phph 不显示某些页面上的某些导航项目。 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
<?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.一种简单的方法是在 header.php 页面上添加条件。
Say you have a variable at the beginning of each page which contains the page name, for instance on "contactpage.php":假设您在每个页面的开头都有一个包含页面名称的变量,例如在“contactpage.php”上:
$page = 'contact';
(note there is also a way to get the name of the current page on the $_SERVER
superglobal variable) (注意还有一种方法可以在
$_SERVER
超全局变量上获取当前页面的名称)
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.