I have a menu that i'm including in my site pages, i want to set a style to the active document link in the menu, and this is the way i'm doing that:
<ul>
<li><a href="slider.php" title="Slider" class="<?php
if ($_SERVER["REQUEST_URI"] == ("/cms/app/slider.php")){echo 'active' ;
}else{ 'not-active';} ?>">Slider</a></li></ul>
So, this works as expected, when "slider.php" is an static document, but is not, it could be "slider.php?url=some-slide-in-db" also; or "store.php?id=4" (or any other id number in db), i just don't know how to implement this method in dynamic pages. ¿Can you give me a hand? thanks!
@Sam i used your clue and it works perfect! code:
<?php $urlsite=$_SERVER["QUERY_STRING"]; ?>
<li><a href="slider.php" title="Slider" class="<?php
if ($_SERVER["REQUEST_URI"] == ("/campanario/cms/app/slider.php") | $_SERVER["REQUEST_URI"] == ("/campanario/cms/app/slider_edit.php?$urlsite")){echo 'active' ;}
else{ 'not-active';} ?>">Slider</a></li>
Thanks!
Try something like this for your if test.
if (substr($_SERVER["REQUEST_URI"],0,strpos("?", $_SERVER["REQUEST_URI"]) == ("/cms/app/slider.php"))
This basically will take the contents of $_SERVER["REQUEST_URI"]
up to the first occurance of ?
and use that for your if condition.