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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.