0

Hi there,

My PHP is appalling/non-existant. I have a HTML website with a PHP header that I've 'included' on all the pages. The problem is that this header colours red whichever page we are currently on, defined under the CSS as being 'active'.

Therefore, from what I see, I need a way in my header.php file to be able to see what webpage is currently open on the site, and use that answer to set active on or off.

e.g.,

IF current webpage = about.php THEN set about.php to active
else
IF current webpage = home.php THEN set home.php to active
...etc, etc.

Is there a relatively simple way to accomplish this?

1
Contributor
3
Replies
12
Views
2 Years
Discussion Span
Last Post by James_43
0

So far, this is one link on my navigation bar:

<li class="nav-parent"><a "class="active" href="index.html">Strong Links</a>

This is the active one at the homepage.

I then made some PHP code to return the name of the current page:

<?php
function curPageURL() {
    $pageURL = 'http';
    $pageURL .= "://Strong-Links.org";
    $pageURL .=$_SERVER["SERVE_NAME"].$_SERVER["REQUEST_URI"];

    return $pageURL;
}
?>

and used that with the following code:

<?php
                curPageURL();
                if $pageURL = "http://test.strong-links.org/index2.php"
                    {echo "class="active"";}
                    else {echo "";} ?> href="index.html">Strong Links</a>

</li>

...But this doesn't seem to do anything :/

0

Ah, sorry to keep coming back here, but I've made more progress and it has ended in distaster!

See for yourself, Strong-Links.org - all the links are active. Here is the code for the HTML header:

<nav id="nav-wrap">
                    <ul class="nav" id="nav">
                        <li class="nav-parent"><a

            <?php

                if ($pageURL = "http://strong-links.org/index.php")
                    {
                        echo 'class="active"'; }
                    else {
                        echo ' '; }

            ?>
            href="index.php">Strong Links</a>

                        </li>
                        <li class="nav-parent"><a

            <?php

                if ($pageURL = "http://strong-links.org/about.php")
                    {
                        echo 'class="active"'; }
                    else {
                        echo ' '; }

            ?>

            href="about.html">About Us</a>

                        </li>
                        <li class="nav-parent"><a href="#">Projects</a>
                <ul>
                    <li><a href="synergy.html">Project Synergy</a></li>
                    <li><a href="iOS.html">Strong Links iOS</a></li>
                    </ul>

                        </li>
                        <li class="nav-parent"><a

            <?php

                if ($pageURL = "http://strong-links.org/volunteer.php")
                    {
                        echo 'class="active"'; }
                    else {
                        echo ' '; }

            ?>

            href="volunteer.html">Volunteer</a>

                        </li>
                        <li><a

            <?php

                if ($pageURL = "http://strong-links.org/contact.php")
                    {
                        echo 'class="active"'; }
                    else {
                        echo ' '; }

            ?>

            href="contact.html">Contact</a></li>
                        <li class="last donate"><a

            <?php

                if ($pageURL = "http://strong-links.org/donate.php")
                    {
                        echo 'class="active"'; }
                    else {
                        echo ' '; }

            ?>

             href="donate.html">Donate</a></li>
                    </ul>                
                </nav>
0

Okay - false alarm! I fixed everything myself.

Simply need to pass the results of the PHP function to a variable:

$pageURL = curPageURL();
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.