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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?