Jump to content

simple nuwbe question, change link depending on curent page


Stripy42

Recommended Posts

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
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.
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]<?php
function 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]

Regards
Rich

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.