I want to make a Navigation system using php. I have it on html , but i am having problems to edit it for every page. i want to include it on every page usng php here is the html code <ul class="mainmenu"> <li id="current" class="level2 item1"><a href="/index.html">Home</a></li> <li class="level2 item10"><a href="/soft.html"">Softwares</a></li> <li class="level2 item11"><a href="/stats/downloads.php">CS Tools</a></li> <li class="level2 item12"><a href="/forum/index.php">Forum</a></li> <li class="level2 item14"><a href="">Contact Us</a></li> </ul> Code (markup): now as u can see there is an id names as "current" . I want it to work like this. include_once "nav.php"; <?php include"$home"; ?> -> this one should include whole nav system and make the id of first link to Current. on another page of my website. include_once "nav.php"; <?php include"$soft"; ?> -> this one should include whole nav system and make 2nd link's id to current. can anyone please help me ??
php won't work that way you can put <ul class="mainmenu"> <li id="current" class="level2 item1"><a href="/index.html">Home</a></li> <li class="level2 item10"><a href="/soft.html"">Softwares</a></li> <li class="level2 item11"><a href="/stats/downloads.php">CS Tools</a></li> <li class="level2 item12"><a href="/forum/index.php">Forum</a></li> <li class="level2 item14"><a href="">Contact Us</a></li> </ul> Code (markup): onm nav.php but when you include nav.php, the whole code will get included. to change the id accordingly, make it a variable, and pass the value to it. so something like nav.php <ul class="mainmenu"> <li id="$navid" class="level2 item1"><a href="/index.html">Home</a></li> <li class="level2 item10"><a href="/soft.html"">Softwares</a></li> <li class="level2 item11"><a href="/stats/downloads.php">CS Tools</a></li> <li class="level2 item12"><a href="/forum/index.php">Forum</a></li> <li class="level2 item14"><a href="">Contact Us</a></li> </ul> Code (markup): then on your other file $navid = $home or $navid = home include nav.php
no you dont understand. i want the id to be chnaged to "current" on different pages. for example on index.php it should change the id of first link to current. and on soft.html it should change the id of second link to current and remove the id of first link. i think if and else statement would work here.
He didn't understand, but michaeljdennis did. Did you read the article he posted? It was exactly what you wanted. Actually I think the method described in the article is slightly inefficient in that it needlessly checks the page name after it has already been set. I would suggest using a switch rather than multiple IFs. How you implement that exactly will depend on your templating engine (if any). Here is an example of my code: if(isset($page)) { switch ($page) { case 'INDEX': break; case 'BROWSE': break; case 'REGISTER': break; case 'LOGIN': break; default: $page = ''; } if(!empty($page)) $template->assign_tags(array($page.'_SELECTED' =>'class="selected"')); } Code (markup): (This is all specific to my classes etc, but it should illustrate my point. That code is about 5 minutes old and not bug-tested so don't blindly copy chunks of it! Good luck! Edit: Just to make things clear, you stick something similar to the above code in whatever PHP include you are using for common processing, then set $page before the include in your actual end-user PHP pages. Example: $page = 'HOME'; include('common.php'); //Stuff.
yeah thanks i already read the article. and just testing needed. already updated my codes. and one more thing please. i also want to update a class on a seperate navigation system. can you help me? the code is : <ul class="mainmenu"> <li class="level1 item2 parent active" style="background: url('images/menu_item1_bg.png') no-repeat;"><a class="slider" href="index.html">Home</a></li> <li class="level1 item4 parent" style="background: url('images/menu_item2_bg.png') no-repeat;"><a class="slider" href="/soft.html">Softwares</a></li> <li class="level1 item6 parent" style="background: url('images/menu_item3_bg.png') no-repeat;"><a class="slider" href="/stats/downloads.php">CS Tools</a></li> <li class="level1 item7 parent" style="background: url('images/menu_item4_bg.png') no-repeat;"><a class="slider" href="/forum/index.php">Forum</a></li> <li class="level1 item8 parent" style="background: url('images/menu_item5_bg.png') no-repeat;"><a class="slider" href="">Contact Us</a></li> </ul> Code (markup): Now as you can see there is a class called active on home's tab. I want this class to be added on soft's tab when clicked , and to be removed from home's tab. can you help me? remember just updating of "active" is needed , everything remains same.
Isn't that essentially the same as your initial problem except with a different HTML class name inserted? It looks like you can just reuse the code you've currently got for the initial problem (You might want to consider turning it into a function if you have nested tab navigation or something along those lines).
hey michealdennis , +rep coming for you. i needed to customize the code a bit. but i got it working thanks.
No problem man! I've used that technique quite a few times now. Enjoi! EL OH EL at teh guy asking for payment!!1!