Jump to content
xisto Community
Sign in to follow this  
Ahsaniqbalkmc

How To Make A Link Pointing To Current Page Inactive

Recommended Posts

I have limited knowledge of PHP and I am trying to learn more of it. I have had an irritating problem from the time I created my first website. I create a list of links to different pages, and I add the list to all the pages included in the list. The problem is that when someone clicks on a link and is carried to the target page, the link that points to the same page is still acitve. This makes me feel that the website may look very unprofessional and I don't want to gain such reputation for my website.When the list of links was small, I added an if condition for each of the link which confirms the address of the current page and compares it with the anchor text of the link. If the condition is true, the output is only a string but when it is false, a proper link is the output.This method works fine but as the list is growing large, I have started to think that it is not an efficient way of doing this. So I am now looking for something more efficient and professional, that can achieve this for me.I have done some research on it and I have found that the trick could be achieved by javascript. Can this be achieved by using php. Which one would be easier to follow.

Share this post


Link to post
Share on other sites

If you want to do it with PHP, you need the links to be stored in the DB and when parsing them just use one if condition if currently requested page is one on that page?A simple way is to create an Array of links, if you don't want a database and use that array, foreach array value generate the links list and if it matches the link, make it look differently.Also you can achieve this with javascript or just simply with jquery by adding a class active or something to that link, the current url can be also fetched with javascript from window.location object.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.