Stripy42 Posted September 13, 2006 Share Posted September 13, 2006 Hello, I've ben trying to do something really simple but can't find out how.I want to use php to insert the wesites links at the top of every page (easy "include" done that bit)But I want it to not show or gray out the link to the current page.I figured some sort of "if curent site = home.php then "nothing" else echo [code]<a href whatever>stuff</a>[/code]But the actual code needed is evading me. ???Thanks Quote Link to comment https://forums.phpfreaks.com/topic/20631-simple-nuwbe-question-change-link-depending-on-curent-page/ Share on other sites More sharing options...
zq29 Posted September 13, 2006 Share Posted September 13, 2006 A simple example would be:[code]<?phpecho (strpos($_SERVER['PHP_SELF'],"home.php")) ? "Home" : "<a href='home.php'>Home</a>";?>[/code]Although there are better ways to go around the whole idea. Quote Link to comment https://forums.phpfreaks.com/topic/20631-simple-nuwbe-question-change-link-depending-on-curent-page/#findComment-91146 Share on other sites More sharing options...
Stripy42 Posted September 13, 2006 Author Share Posted September 13, 2006 Cool, So that will be like an if for each and every link, I can see what you mean about better ways.I was thinking I could get the document name once at the begining, and then compare it for each link to the actual href in the link.That way I won't add an extra chance to create a mistake by haveing to type the link twice. Quote Link to comment https://forums.phpfreaks.com/topic/20631-simple-nuwbe-question-change-link-depending-on-curent-page/#findComment-91156 Share on other sites More sharing options...
HuggieBear Posted September 13, 2006 Share Posted September 13, 2006 I'd go for something like this:index.php[code]<?php include_once('functions.php'); $page = $_SERVER['PHP_SELF']; createnav($page);?>[/code]Then functions.php looks like this:[code]<?phpfunction createnav($var){ preg_match("/([^\/]+)$/", $var, $missing_page); $pages = array( "Home" => "index.php", "Contact Me" => "contact.php", "Google" => "http://www.google.co.uk" ); foreach ($pages as $page => $link){ if ($link != $missing_page[0]){ echo "<a href=\"$link\">$page</a><br>"; } }}?>[/code]This should work. You just include a list of pages in the array inside the function. It's not ideal if you have a lot of pages, but could be adapted.[size=8pt][color=red][b]EDIT: [/b][/color]I've updated the above code and it should work fine.[/size]RegardsRich Quote Link to comment https://forums.phpfreaks.com/topic/20631-simple-nuwbe-question-change-link-depending-on-curent-page/#findComment-91160 Share on other sites More sharing options...
Stripy42 Posted September 15, 2006 Author Share Posted September 15, 2006 Yay! that is excilent, thank you. :D Quote Link to comment https://forums.phpfreaks.com/topic/20631-simple-nuwbe-question-change-link-depending-on-curent-page/#findComment-92255 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.