简体   繁体   English

当通过包含所有标题时,将当前类别分配给导航中的当前页面<?php include()?>

[英]assign a class of current to the current page in the navigation when all headers are included via <?php include()?>

I have all the headers and the top navigation included in the page with PHP 我具有PHP页面中包含的所有标题和顶部导航

I want to assign a class to the <li class="current"> 我想将一个类分配给<li class="current">

so i have a list of <li> 's and the current page should get a class of "current" 所以我有一个<li>的列表,当前页面应该得到“当前”类

and the body should get a class of the current page 并且正文应该得到当前页面的类

for http://www.mysite.com/home = the body should be <body class"home"> and so on 对于http://www.mysite.com/home =正文应为<body class"home"> ,依此类推

Thanks 谢谢

You might use something like: 您可能会使用类似:

<?
    $parts = explode("/", strtolower(preg_replace("/[^\\/\w]/", "", $_SERVER["REQUEST_URI"])));
?>

[...]

<body class="<? echo $parts[0] ?>">

You can similarily compare the $_SERVER["REQUEST_URI"] to the link of each of your navigation items. 您可以类似地将$ _SERVER [“ REQUEST_URI”]与每个导航项的链接进行比较。 Note that the $_SERVER["REQUEST_URI"] can be spoofed by the client , so make sure you kick out anything strange before using it or displaying it back to the page. 请注意,$ _SERVER [“ REQUEST_URI”]可以由客户端欺骗 ,因此请确保在使用任何奇怪的东西之前将其踢出去或将其显示回页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM