rickphp Posted September 10, 2009 Share Posted September 10, 2009 Hi, This may sound a little confusing but I will explain as best as I can! I am using includes to build up my pages, for example the contact page would be made up of the following includes; header.tpl, contact.tpl and footer.tpl What I am trying to do is make it so that when I navigate between pages the relative navigation button will be set to "active" in the header.tpl file, so that the user can see what page they are on when they look at the navigation buttons. If this isn't possible then any other way of acheiving the same outcome is fine. But this has got me a little stuck. So if I was on the home page the header would be something like this (I've removed a lot of div tags etc to make things as simple as possible for any one who can help). <a href="home" title="" class="active">Home</a><a href="example" title="">Example</a><a href="contact" title="">Contact</a> If i then navigated to the contact page the header should look like this: <a href="home" title="">Home</a><a href="example" title="">Example</a><a href="contact" title="" class="active">Contact</a> Hopefully you guys will be able to help! Thanks in advance for anyone who can help! Quote Link to comment https://forums.phpfreaks.com/topic/173836-solved-help-setting-data-in-header-file-from-a-seperate-file/ Share on other sites More sharing options...
mikesta707 Posted September 10, 2009 Share Posted September 10, 2009 are the links static URLS, like <a href="mysite.com/news.php">news</a> or dynamically gotten via get variables like <a href="index.php?id=news">news</a> ? Quote Link to comment https://forums.phpfreaks.com/topic/173836-solved-help-setting-data-in-header-file-from-a-seperate-file/#findComment-916322 Share on other sites More sharing options...
rickphp Posted September 10, 2009 Author Share Posted September 10, 2009 static urls Quote Link to comment https://forums.phpfreaks.com/topic/173836-solved-help-setting-data-in-header-file-from-a-seperate-file/#findComment-916345 Share on other sites More sharing options...
mikesta707 Posted September 10, 2009 Share Posted September 10, 2009 well you can do $url = $_SERVER["REQUEST_URI"]; that will give you the page you are on (for example if at www.mysite.com/news.html that will return news.html) and you can do a switch statement to decide which gets the class Quote Link to comment https://forums.phpfreaks.com/topic/173836-solved-help-setting-data-in-header-file-from-a-seperate-file/#findComment-916350 Share on other sites More sharing options...
rickphp Posted September 10, 2009 Author Share Posted September 10, 2009 I'm not sure I know how do to that, would you be kind enough to provide an example of this coding and how it would work? Quote Link to comment https://forums.phpfreaks.com/topic/173836-solved-help-setting-data-in-header-file-from-a-seperate-file/#findComment-916363 Share on other sites More sharing options...
mikesta707 Posted September 10, 2009 Share Posted September 10, 2009 yeah no problem, just post the header page so I know how it is scructured Quote Link to comment https://forums.phpfreaks.com/topic/173836-solved-help-setting-data-in-header-file-from-a-seperate-file/#findComment-916364 Share on other sites More sharing options...
rickphp Posted September 10, 2009 Author Share Posted September 10, 2009 I have PM'd you. Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/173836-solved-help-setting-data-in-header-file-from-a-seperate-file/#findComment-916371 Share on other sites More sharing options...
rickphp Posted September 10, 2009 Author Share Posted September 10, 2009 Not heard anything back, did you get the message? If anyone else could help I would really appreciate it as mikesta707 has just gone offline. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/173836-solved-help-setting-data-in-header-file-from-a-seperate-file/#findComment-916401 Share on other sites More sharing options...
cbolson Posted September 10, 2009 Share Posted September 10, 2009 Hi, I would suggest that you make an array of menu items like this: $menu=array(); $menu[home.php]="Home"; $menu["example.php"]="Example"; $menu["contact.php"]="Contact" etc. Then loop through the array to create the html: foreach($menu AS $url=>$txt){ echo '<a href="'.$url.'"'; if($url==$_SERVER["REQUEST_URI"]) echo ' class="active"'; echo '>'.$txt.'</a>'; } Not tested that code but it should work. Chris Quote Link to comment https://forums.phpfreaks.com/topic/173836-solved-help-setting-data-in-header-file-from-a-seperate-file/#findComment-916409 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.