[英]PHP Include , but only certain things
我正在使用 php include 在我的网页上包含页眉和页脚。 我在所有标题上都有一个导航栏,想知道是否有办法让 header.phph 不显示某些页面上的某些导航项目。 例如,人们不需要从联系人页面导航到联系人页面,因此不需要此导航项。 希望有人可以提供帮助。
索引.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');
?>
头文件
!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>
一种简单的方法是在 header.php 页面上添加条件。
假设您在每个页面的开头都有一个包含页面名称的变量,例如在“contactpage.php”上:
$page = 'contact';
(注意还有一种方法可以在$_SERVER
超全局变量上获取当前页面的名称)
然后你可以有条件地在导航栏中打印你的链接:
<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.