Skip to main content
February 28, 2007
Question

PHP code for links with current state

  • February 28, 2007
  • 4 replies
  • 515 views
I have created a <?php include(menu.php) ?> that is in my pages. In my menu.php page which is an unordered list of my menu links, which looks like this, see below.

<ul>
<li><a href="/index.php" id="current">Home</a></li>
<li><a href="/lommiinfo/index.php">LOMMI Info</a></li>
<li><a href="/calendar/index.php">Calendar</a></li>
<li><a href="/resources/index.php">Resource Centre</a></li>
<li><a href="/articles/index.php">Articles</a>
<li><a href="/ministries/index.php">Ministries</a></li>
<li><a href="/logincentre/index.php">Login Centre</a></li>
<li><a href="/sitemap/index.php">Site Map</a></li>
</ul>

If you see above in my unordered list in my home link there a id=”current” which shows the Home has a current state status.

What I am asking for, is there a php function or php if statement that can make the current state show when you are at the appropriate page that is in the a href link?

Thank you,
AdonaiEchad
This topic has been closed for replies.

4 replies

Inspiring
March 3, 2007
AdonaiEchad wrote:

> I have created a <?php include(menu.php) ?> that is in my pages. In my
> menu.php page which is an unordered list of my menu links, which looks like
> this, see below.
>
>

  • >
  • <a href="/index.php" id="current">Home</a></li>
    >
  • <a href="/lommiinfo/index.php">LOMMI Info</a></li>
    >
  • <a href="/calendar/index.php">Calendar</a></li>
    >
  • <a href="/resources/index.php">Resource Centre</a></li>
    >
  • <a href="/articles/index.php">Articles</a>
    >
  • <a href="/ministries/index.php">Ministries</a></li>
    >
  • <a href="/logincentre/index.php">Login Centre</a></li>
    >
  • <a href="/sitemap/index.php">Site Map</a></li>
    >

>
> If you see above in my unordered list in my home link there a id=?current?
> which shows the Home has a current state status.
>
> What I am asking for, is there a php function or php if statement that can
> make the current state show when you are at the appropriate page that is in the
> a href link?
>
> Thank you,
> AdonaiEchad
>
>

CSS:
<style>
#current{
background:red;
color:green;
}
</style>

Js:
<script>
onload=function(){
var d=document.getElementById("current")
d.style.backgroundColor="red"
d.color="green";
}
</script>
Mick
Inspiring
March 1, 2007
> Hi.
> I'm sorry to disturb you in a thread it's not mine, but I need an answer
> to an old problem:
> http://groups.google.it/group/macromedia.dreamweaver.appdev/browse_frm/thread/77d1647349529227
> Does someone find the solution to that "UNIDENTIFIED ERROR"???
> I don't!! :-(
> (I'm running XP+IIS5+php5+mysql4, and everything works, with phpmyadmin
> and with mysqladministrator too)
> Thanks if you reply.

I didn't mention I'm using DwMX.


Inspiring
March 1, 2007
> David Powers, Adobe Community Expert
> Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
> Author, "PHP Solutions" (friends of ED) http://foundationphp.com/

Hi.
I'm sorry to disturb you in a thread it's not mine, but I need an answer to
an old problem:
http://groups.google.it/group/macromedia.dreamweaver.appdev/browse_frm/thread/77d1647349529227
Does someone find the solution to that "UNIDENTIFIED ERROR"???
I don't!! :-(
(I'm running XP+IIS5+php5+mysql4, and everything works, with phpmyadmin and
with mysqladministrator too)
Thanks if you reply.


Inspiring
March 1, 2007
AdonaiEchad wrote:
> What I am asking for, is there a php function or php if statement that can
> make the current state show when you are at the appropriate page that is in the
> a href link?

<a href="/index.php" <?php if($_SERVER['SCRIPT_NAME'] == '/index.php')
echo 'id="current"'; ?>>Home</a>

--
David Powers, Adobe Community Expert
Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
March 1, 2007
Thank you David, it works perfectly. One other question I have that I just realized is this. Because I have a php include which is menu, what if I have another menu underneath lets say the LOMMI Info. So for example...

For menu.php is the following as you had demonstrated.
<ul>
<li><a href="/index.php" <?php if($_SERVER['SCRIPT_NAME'] == '/index.php') echo 'id="current"'; ?>>Home</a></li>
<li><a href="/lommiinfo/index.php" <?php if($_SERVER['SCRIPT_NAME'] == '/lommiinfo/index.php') echo 'id="current"'; ?>>LOMMI Info</a></li>
<li><a href="/calendar/index.php" <?php if($_SERVER['SCRIPT_NAME'] == '/calendar/index.php) echo 'id="current"'; ?>>Calendar</a></li>
<li><a href="/resources/index.php" <?php if($_SERVER['SCRIPT_NAME'] == '/resources/index.php') echo 'id="current"'; ?>>Resource Centre</a></li>
<li><a href="/articles/index.php" <?php if($_SERVER['SCRIPT_NAME'] == '/articles/index.php') echo 'id="current"'; ?>>Articles</a>
<li><a href="/ministries/index.php" <?php if($_SERVER['SCRIPT_NAME'] == '/ministries/index.php') echo 'id="current"'; ?>>Ministries</a></li>
<li><a href="/logincentre/index.php" <?php if($_SERVER['SCRIPT_NAME'] == '/logincentre/index.php') echo 'id="current"'; ?>>Login Centre</a></li>
<li><a href="/sitemap/index.php" <?php if($_SERVER['SCRIPT_NAME'] == '/sitemap/index.php') echo 'id="current"'; ?>>Site Map</a></li>
</ul>

Now, how does it work if there is a submenu. If I have a include also for info.php such as below

<ul>
<li><a href="/lommiinfo/affiliates/index.php">Affiliates</a></li>
<li><a href="/lommiinfo/about/index.php">About Us</a></li>
</ul>

So lets say the menu looks like this...

Home | LOMM Info | Calendar | Resource Centre | Articles | Ministries | Login Centre | Site Map


Now, there is a sub menu that shows up when you click on LOMM Info like so.

Home | LOMM Info | Calendar | Resource Centre | Articles | Ministries | Login Centre | Site Map
Affiliates | About Us

Is there a way to make the current show up for both the LOMMI Info tab as well as lets say when you are on the Affiliates page? If the affiliates is selected can the above parent folder be under current as well? Is this possible?

Thank you,
AdonaiEchad