douding_1073 2016-03-31 19:42
浏览 93
已采纳

在使用header.php页面时,如何使用PHP定义导航栏的“活动”选项卡

I'm trying do a navigation bar that has a "current" class to whichever page we're on. But the navigation bar is on a header.php page and I use an include tag to bind pages with the header.

How would I go about this? I assumed I would use something similar to;

if(strpos($_SERVER['REQUEST_URI'], 'index') !== false){;

But I'm not confident enough to tackle this on my own.

https://jsfiddle.net/zo5oy46q/

Thankyou!

  • 写回答

1条回答 默认 最新

  • dongxun1244 2016-03-31 20:13
    关注

    At the top of every page create a variable called for example $page_name, and assign a name to each page.

    Then in every tab add the current class in base of the page's name.

    Example:

    <a href="/home" class="<?php echo $page_name == 'home' ? 'current' : '' ?>"></a>
    <a href="/contact" class="<?php echo $page_name == 'contact' ? 'current' : '' ?>"></a>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示