Hey everyone,

I have a question about how to dynamically change a link based on the current page. Sort of like the "breadcrumb" feature in wordpress. However I don't want it to read as follows: "index.php", "about-us.php"..ect. I want the link to be something like "Home" "About Us" ..ect. How do I go about this?

Recommended Answers

All 3 Replies

The typical anchor element would look something like this...

 <a herf="index.php">Home</a>

What is happening on the home page that you need to know what page you are on? In other words, are you using a generic PHP page and generating content based upon some query string parameter? I'm not understanding what you mean by based on current page.

Anyway to get the current page, use

 $_SERVER['PHP_SELF']

The filename output is relative to the root of the document.

to get url like www.test.come/home or www.test.come/about here is what you need to do.

first create a folderin the main directory, and renamed it home now the url for this directory will looks like www.test.come/about

okay so what we need to do is rename your about-us.php to index.php
and move the file to about folder we just created. and in your browser,
if you are using localhost,
type http://localhost/about and see what happens. you can link to that file with a href

<a href="http://localhost/about">about us</a>

you dont need to mention http://localhost/about/index.php, just http://localhost/about should do the work.

cheers

Here are what my links look like as of right now:

<li>
    <a href="">
        <?php
            function curPageName() {
            return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
            }
            echo curPageName();
        ?>
    </a>
</li>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.