homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Hide a link conditional by its url

10+ Year Member

Msg#: 4938 posted 4:22 am on Sep 2, 2004 (gmt 0)

Hi all
Is it possible to hide an ahref link with php conditional on what the url is?
I use an off the shelf CMS that will only allow searching pages if the parent category is published as "visible". I don't want the parent category link in the navigation though so I was wondering if PHP could hide the link, maybe conditional on what the link (URL) is.



10+ Year Member

Msg#: 4938 posted 11:00 am on Sep 2, 2004 (gmt 0)

How bout righting into the script that makes it visible or invisible a new robot.txt? As long as its a respectible search engine if it says dont search it wont search.


WebmasterWorld Senior Member trillianjedi us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4938 posted 11:18 am on Sep 2, 2004 (gmt 0)


I have a coder building a similar thing as we speak. StickyMail me in a week or so if you haven't found an alternative solution by then and I'll send you the code.

What I'm having built is something that logically works like this:-

1. If the link is to my domain, then echo out the straight link including any requested anchor text, e.g.:-

<a href="http://trillians/widgets.html">Trillian's Widgets</a>

Get's echoed out as it is.

2. If the link is not on one of my domains then echo out the link preceeeded with "http://mydomain/redirect.php?url=" and leave the rest (so anchor text is the same), eg:-

<a href="http://someone-else/widgets.html">A N Other's Widgets</a>

gets echoed out as:-

<a href="http://trilian/redirect.php?url=http://someone-else/widgets.html">A N Other's Widgets</a>

This is for a forum (tracking outbounds), but it would work for what you need to do, you would just need to edit it to echo out nothing if the URL matches the URL that you want to supress.


PS Welcome to Webmasterworld!


10+ Year Member

Msg#: 4938 posted 10:05 pm on Sep 2, 2004 (gmt 0)

Thanks TJ
Looks like it's exactly what I need. As soon as it's sorted I'd love to check out the code if possible.
Thankyou very much.


10+ Year Member

Msg#: 4938 posted 6:01 pm on Sep 4, 2004 (gmt 0)

This is what I did.
In any template I want to hide a specific link (in this case "Toolkit")I put the following at the top of the page:

<?php $hidePage="Toolkit";?>

I use the following css:

#hidden {display: none;}

Then in the nav:

<div<?php if ($hidePage=="$cat_name$")
echo " id=\"hidden\"";?>><a href="$url_index$">$cat_name$</a></div>

$cat_name$ is the placeholder in my CMS that dynamically populates the navigation. The PHP code will find the item "Toolkit" and wrap it with the css #hidden class.


WebmasterWorld Senior Member 10+ Year Member

Msg#: 4938 posted 5:22 pm on Sep 6, 2004 (gmt 0)

looks like that'll work well enough - except you might want to use single quotes, double quotes could put php into a parsing mode where it wants to get a variable with the name $cat_name$ (dunno, might not with that $ at the end, but single quotes would be safer, not to mention faster) -- you sure you want to hide it though with css? Maybe se's get suspicious? You can just not output it in the first place.

if($hidepage <> '$cat_name$') echo '<a href="$url_index$">$cat_name$</a>';

A second thought - this depends on how your templating thingie works, if it buffers the output and then replacing or replacing as it goes - if it's replacing as it goes, it'd probably be more like

if($hidepage <> $cat_name$) echo '<a href="'.$url_index.'">'.$cat_name.'</a>';

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved