使用php页面上的类处于活动状态 [英] Class active when on page using php

查看:44
本文介绍了使用php页面上的类处于活动状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含文件,其中包含我网站的页眉和页脚.但是在标题中,我使用了一个活动类,以便在该页面上更改菜单项.如何使用一个包含文件来实现这一目标?使用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页面上的类处于活动状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆