2016-07-15 38 views
1

我有我在的header.php所有頁面的基本導航欄,所以如何做到這一點使它活動讓人們知道他們是在通過導航欄使導航欄活躍在php include_once標籤

HTML

哪一頁
<ul class="menu"> 
    <li><a href="index.php">HOME</a></li> 
    <li><a href="features.php">SMARTRETAIL FEATURES</a></li> 
    <li><a href="faq.php">FREQUENTLY ASKED QUESTIONS</a></li> 
    <li><a href="customers.php">CUSTOMERS</a></li> 
    <li><a href="contactus.php">CONTACT US</a></li> 
    <li><a href="userguide.php">USER GUIDE</a></li> 
    </ul> 

CSS

ul.menu { 
    list-style-type: none; 
    margin: 0; 
    padding: 0; 
    overflow: hidden; 
    background-color: #333; 
} 

ul.menu li { 
    float: left; 
    border-right: 1px solid black; 
} 

ul.menu li a { 
    display: block; 
    color: white; 
    text-align: center; 
    padding: 14px 16px; 
    text-decoration: none; 
} 

ul.menu li a:hover:not(.active) { 
    background-color: #000000; 
} 

.active { 
    background-color: #2676f5; 
} 
+0

是這個純PHP或使用CMS –

回答

0

如果PHP是指這裏的答案How to set current page "active" in php

在短

// set this above the include of the nav 
$activePage = "offnungszeiten.php"; 

$pages = array(); 
$pages["index.php"] = "Öffnungszeiten"; 
$pages["features.php"] = "Sauna"; 
$pages["faq.php"] = "Frauensauna"; 
$pages["custom.php"] = "Beauty Lounge"; 
$pages["feiertage.php"] = "Feiertage"; 


//menu.php 
<?php foreach($pages as $url=>$title):?> 
    <li> 
     <a <?php if($url === $activePage):?>class="active"<?php endif;?> href="<?php echo $url;?>"> 
     <?php echo $title;?> 
     </a> 
    </li> 

<?php endforeach;?> 
0

嘗試這種情況:

<ul class="menu"> 
<li><a href="index.php" class="<?php echo ($_SERVER['REQUEST_URI'] == '/index.php') ? 'active':'' ?>">HOME</a></li> 
<li><a href="features.php" class="<?php echo ($_SERVER['REQUEST_URI'] == '/features.php') ? 'active':'' ?>">SMARTRETAIL FEATURES</a></li> 
<li><a href="faq.php" class="<?php echo ($_SERVER['REQUEST_URI'] == '/faq.php') ? 'active':'' ?>">FREQUENTLY ASKED QUESTIONS</a></li> 
<li><a href="customers.php" class="<?php echo ($_SERVER['REQUEST_URI'] == '/customers.php') ? 'active':'' ?>">CUSTOMERS</a></li> 
<li><a href="contactus.php" class="<?php echo ($_SERVER['REQUEST_URI'] == '/contactus.php') ? 'active':'' ?>">CONTACT US</a></li> 
<li><a href="userguide.php" class="<?php echo ($_SERVER['REQUEST_URI'] == '/userguide.php') ? 'active':'' ?>">USER GUIDE</a></li>