[英]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.