Jump to content

Menu and Request URI


djp1988

Recommended Posts

Hi, this is my site:http://www.actionscriptcoding.com/I have a menu and when you rollover the items, they turn blue, okay, to make the user aware of where about he is on the site I made my menu a little more dynamic as i get the url with the php script and check it against a pre defined page and if it matches then i force the css properties onto the menu in order to retain the rollover-kind state, all works well, except that I am verifying like so:

<?php $ad = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];  $urlASC = "http://www.actionscriptcoding.com/";  $left = "background-position:0% -42px;";  $right = "background-position:100% -42px;"; ?>  <ul>	<li><a style="<?php if ($ad == $urlASC ."index.php"){    print "$left";   }elseif ($ad == $urlASC .""){   print "$left";   }else{   print "";} ?>" href="http://www.actionscriptcoding.com"><span style="<?php    if ($ad == $urlASC ."index.php"){    print "$right";   }elseif ($ad == $urlASC .""){   print "$right";   }else{   print "";} ?>">Home</span></a></li>....	<li><a style="<?php if ($ad == $urlASC ."experiments.php"){    print "$left";   }else{   print "";} ?>" href="http://www.actionscriptcoding.com/experiments.php"><span style="<?php    if ($ad == $urlASC ."experiments.php"){    print "$right";   }else{   print "";} ?>">Experiments</span></a></li>

But when I go into the last option I put on the code, into experiments.php, there are more pages that are saved in www.actionscriptcoding/Experiments/....So how can I retain my method of fetching the URL but for this particular one, just check part of the URL to see if we're in the directory /Experiments and if so print the css properties.I hope you understand what I am looking for, if not, you will quickly see, go here: http://www.actionscriptcoding.com/ > Click on Experiments in the menu, and that tab stays blue once the new page has loaded, but then if you select the page called 'February (3)' from the 'Archives' menu on the right, then you'll notice that the tab Experiments has gone back to being white, well I want that to stay blue !!!Please help me ! Thanks

Link to comment
Share on other sites

It's easier to use IDs then to check for everything. Put IDs on each LI element.<li id="menu_page1"><a ...></li><li id="menu_page2"><a ...></li><li id="menu_page3"><a ...></li>Have your <head> tag include a section like this:<style type="text/css">#menu_<?php echo $page_name; ?>{ background: blue;}</style>Then before you print the head, define the $page_name variable to be "page1", "page2", etc to match the LI you want to highlight. Then you can highlight whatever you want on any page.

Link to comment
Share on other sites

Hi, thanks for the answer, but that won't work here for 2 reasons, the first being, that I am including a file called 'header' which is the beginning of the document until after </head>And secondly, I have 2 background images one for the left side of the tab and one for the right, so assigning css to only the id of the <li> element would not get the job done.

Link to comment
Share on other sites

I've got round the pproblem, in my header.php I have this in the head:

<style type="text/css"><?php if (defined('MENU')) {print MENU;}else{print''; } ?></style></head>

and in my menu I have added an ID for only the experiments tab:

<li id="experiments"><a style="<?php if ($ad == $urlASC ."experiments.php"){    print "$left";   }else{   print "";} ?>" href="http://www.actionscriptcoding.com/experiments.php"><span style="<?php    if ($ad == $urlASC ."experiments.php"){    print "$right";   }else{   print "";} ?>">Experiments</span></a></li>

and in all the pages within the directory experiments I have:

define ('MENU', '#experiments a {background-position:0% -42px;}#experiments a span {background-position:100% -42px;}');

and so yea, it works, thanks for the clue justsomeguycheck the result out ; www.actionscriptcoding.com

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...