Jump to content

Question about best practice

Whether you're a seasoned veteran or a struggling beginner, Web Radiance is the web development and web design forum for you. You'll find answers to all your HTML, CSS, SEO, and Programming needs. Pull up a chair and stay awhile.

Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

Question about best practice Rate Topic: -----

#1 User is offline   Beavis 

  • W.R. Corporal
  • Group: Members
  • Posts: 167
  • Joined: 24-March 08

Posted 14 July 2008 - 06:34 PM

I`ve seen it mentioned here and in other places that a web page should NOT have a link back to itself.

The problem for me is that I usually use a "PHP include" for the main navigation and header block of each page (saves updating code on umpteen different pages).
I then use an ID tag for the <body> to tell the menu what the current page is, and use CSS rules to give a different state for the appropriate main menu item.

I suppose its possible to write a Javascript routine that looks for any links on the current page back to itself and then delete those anchor nodes from the DOM (but it makes my
head hurt thinking about what such a script would look like :pinch:

My question is, how much of a "coding faux pas" is it really in the first place.

This post has been edited by Beavis: 14 July 2008 - 06:34 PM

0

#2 User is offline   sypher 

  • the owner3r
  • Group: Administrators
  • Posts: 1,578
  • Joined: 04-April 06
  • Location:North Wales, UK
  • Interests:Art, Boxing, MMA, Graphic Design, Web Design etc. ;)

Posted 14 July 2008 - 07:17 PM

What reason is there for not linking back to itself? Most sites use the main logo (like webradiance) to link back to the main page.
sypher design - North Wales Web Design | Latest Work: - Scala Cinema

CSS - Can't See Sh*t
0

#3 User is offline   Beavis 

  • W.R. Corporal
  • Group: Members
  • Posts: 167
  • Joined: 24-March 08

Posted 14 July 2008 - 08:33 PM

View Postsypher, on Jul 15 2008, 09:17 AM, said:

What reason is there for not linking back to itself? Most sites use the main logo (like webradiance) to link back to the main page.


I`m not saying its something I agree with.
Just an opinion that some web designers seem to have that a page should not have a link back to itself.

For the reasons I mentioned I`m inclined to not worry about it.
0

#4 User is offline   haku 

  • 日本語 Ninja
  • Group: Members
  • Posts: 652
  • Joined: 21-September 07
  • Gender:Male
  • Location:Yokohama, Japan

Posted 14 July 2008 - 09:23 PM

If you really don't want the page to link back to itself, you can use the following function to get the current page name:

//returns the filename of the current page
function curPageName()
{
	return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}


This will give you the page name (file name) of the current page. Then, you can test for the current page name, and if it is the page name, output text, and if its not, output a link. For example, if you are on test.php:

echo (curPageName() != "test.php) ? "<a href="test.php">test</a>" : "test";

<a href="http://www.jaypan.com" target="_blank">Jaypan</a>
<a href="http://www.dudes-japan.com" target="_blank">Dudes Japan</a>
0

#5 User is offline   Beavis 

  • W.R. Corporal
  • Group: Members
  • Posts: 167
  • Joined: 24-March 08

Posted 14 July 2008 - 09:37 PM

View Posthaku, on Jul 15 2008, 11:23 AM, said:

If you really don't want the page to link back to itself, you can use the following function to get the current page name:

//returns the filename of the current page
function curPageName()
{
	return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}


This will give you the page name (file name) of the current page. Then, you can test for the current page name, and if it is the page name, output text, and if its not, output a link. For example, if you are on test.php:

echo (curPageName() != "test.php) ? "<a href="test.php">test</a>" : "test";


Thats a nice piece of code.
Have to remember that string function for the future.

Generally speaking though I am wondering whether the additional code plus server hits are really worth it.
Just curious about the consensus of opinion.
0

#6 User is offline   haku 

  • 日本語 Ninja
  • Group: Members
  • Posts: 652
  • Joined: 21-September 07
  • Gender:Male
  • Location:Yokohama, Japan

Posted 14 July 2008 - 11:37 PM

The server hit from the code will be very very minimal. The code is simple, and if/else statements take very little processing power. Even with a large list of links to check, it wouldn't add more than a milliseconds to your processing time. It's more just a pain in the ass to code all that!
<a href="http://www.jaypan.com" target="_blank">Jaypan</a>
<a href="http://www.dudes-japan.com" target="_blank">Dudes Japan</a>
0

#7 User is offline   Catalyst 

  • Codesmith
  • Group: Administrators
  • Posts: 1,049
  • Joined: 04-April 06
  • Gender:Male
  • Location:San Diego

Posted 15 July 2008 - 12:28 AM

I wouldn't worry at all about it.
0

#8 User is offline   haku 

  • 日本語 Ninja
  • Group: Members
  • Posts: 652
  • Joined: 21-September 07
  • Gender:Male
  • Location:Yokohama, Japan

Posted 15 July 2008 - 02:45 AM

I've been thinking that you could refine my code above even more by adding another function. First declare two functions:

//returns the filename of the current page
function curPageName()
{
	return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
}

function outputLink($text, $link)
{
   $val = (curPageName() != $link) ? "<a href="{$link}">{$text}</a>" : $text;
   return $val;
}


Then for each link you can run it through the funtion:

echo outputLink("test", "test.php");
echo outputLink("home", "home.php");
echo outputLink("about us", "about_us.php");


although this function would require some refining if all the pages aren't in the same directory. But a little fine tuning would make it work.
<a href="http://www.jaypan.com" target="_blank">Jaypan</a>
<a href="http://www.dudes-japan.com" target="_blank">Dudes Japan</a>
0

#9 User is offline   Karl Buckland 

  • A.K.A. Sirkent
  • Group: Administrators
  • Posts: 2,145
  • Joined: 04-April 06
  • Gender:Male
  • Location:Kent, UK

Posted 15 July 2008 - 04:48 AM

I too, wouldn't worry about it. I can't imagine a search engine penalising you for doing this. In the worst case - it would simply be ignored.
QUOTE(benbramz @ Aug 17 2007, 07:44 AM) Ive noticed that quite a few people are now adding quotes from the board into their signature. I think its started an new web-radiance craze.. :P
0

#10 User is offline   marcamos 

  • W.R. General
  • Group: Administrators
  • Posts: 2,849
  • Joined: 04-April 06
  • Gender:Male
  • Location:Massachusetts - USA

Posted 15 July 2008 - 07:54 AM

View PostCatalyst, on Jul 15 2008, 01:28 AM, said:

I wouldn't worry at all about it.

0

#11 User is offline   James Mitchell 

  • Legendary
  • Group: Administrators
  • Posts: 922
  • Joined: 26-July 06
  • Gender:Male
  • Location:Fort Wayne, IN

Posted 15 July 2008 - 08:24 AM

View PostCatalyst, on Jul 15 2008, 01:28 AM, said:

I wouldn't worry at all about it.

Posted Image
0

#12 User is offline   haku 

  • 日本語 Ninja
  • Group: Members
  • Posts: 652
  • Joined: 21-September 07
  • Gender:Male
  • Location:Yokohama, Japan

Posted 15 July 2008 - 08:24 AM

Too funny Marc :D
<a href="http://www.jaypan.com" target="_blank">Jaypan</a>
<a href="http://www.dudes-japan.com" target="_blank">Dudes Japan</a>
0

#13 User is offline   jameson 

  • W.R. Corporal
  • Group: Members
  • Posts: 114
  • Joined: 08-July 08
  • Gender:Male
  • Location:Phoenix, AZ
  • Interests:These days I eat, sleep, and breathe web design with no time for much else. I sure dig some good techno, though.

Posted 15 July 2008 - 09:35 AM

I agree not to worry about it too much. I think it's mainly not considered good practice for a page to link back to itself just because it can be a little confusing for the user.

I do the same thing you do, where I use PHP includes for the navigation and then style the link to the current page with CSS by referring to the body ID. I do add this little piece to the CSS, though, to make it look like the page isn't linking back to itself:
cursor:default;

0

#14 User is offline   celandine 

  • W.R. Private
  • Group: Members
  • Posts: 27
  • Joined: 10-July 08
  • Gender:Female
  • Location:Belgrade, Serbia
  • Interests:languages, swimming, shooting, web design, photography, travel

Posted 15 July 2008 - 10:27 AM

ha ha that's clever :D

another way to do it is even simpler - just leave the link to the current page in a rollover state and the user will assume it's not clickable. Chances are he won't even try to hover over it.

I don't think it's a terrible faux pas, I think it's just a little superfluous is all - what purpose can it serve for a page to link to itself? But that's really just nitpicking............
The Seminar on Time Travel will be held three days ago

www.celandinewebdesign.com
0

#15 User is offline   sypher 

  • the owner3r
  • Group: Administrators
  • Posts: 1,578
  • Joined: 04-April 06
  • Location:North Wales, UK
  • Interests:Art, Boxing, MMA, Graphic Design, Web Design etc. ;)

Posted 15 July 2008 - 01:34 PM

It actually helps your onpage seo a little bit, to link back to your pages internally using the keywords you want those pages to rank high for.

Nothing big though, its designers preference. Its not something i would go out my way to solve.
sypher design - North Wales Web Design | Latest Work: - Scala Cinema

CSS - Can't See Sh*t
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • This topic is locked

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users