问题描述
我有一个包含文件,其中包含我网站的页眉和页脚.但是在标题中,我使用了一个活动类,以便在该页面上更改菜单项.如何使用一个包含文件来实现这一目标?使用PHP?
I have an include file that includes the header and footer of my site. But in the header I use an active class to let the menu-item change when on that page. How can you achieve this using one include file? With PHP?
我发现了:
index.php
index.php
<?php $page == 'one'; include('includes/header.php'); ?>
header.php
header.php
<li>
<a <?php echo ($page == 'one') ? "class='active'" : ""; ?>
href="contact.php">Contact</a>/</li>
但是它并没有改变,当我分别在每个页面上使用该类时,它就可以工作了.
But it's not changing, when I just used the class on every page seperately, it worked.
推荐答案
Index.php
Index.php
<?php $page = 'one'; include('includes/header.php'); ?>
$ page ='一个'."=="是比较运算符 http://www.php.net/manual/en/language.operators.comparison.php
$page = 'one'. "==" is a comparison operator http://www.php.net/manual/en/language.operators.comparison.php
Header.php
Header.php
<li><a href="#"<?php if($page == 'one'){ echo ' class="active"';}?>>LINK</a></li>
我觉得这样更干净
这篇关于使用php页面上的类处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!