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/
Inspiring
March 1, 2007
AdonaiEchad wrote:
> 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?

Yes, but you can have only one instance of an ID on the page. So you
need to have two separate IDs or use a class instead.

<a href="/lommiinfo/index.php"
<?php
$path = $_SERVER['SCRIPT_NAME'];
$parts = pathinfo($path);
if($path == '/lommiinfo/index.php' || $parts['dirname'] ==
'lomiinfo') echo 'class="current"'; ?>>LOMMI Info</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 2, 2007
David, your help is greatly appreciated. I did a little bit of tweaking and I was able to work your script. I was thinking what if I place a <?php $home = $_SERVER['SCRIPT_NAME']; ?> in each of my pages, so if there is a different page I would change the $home to $navInfo or what ever I wish.

This is what I've done for my menu.php which is a include for my pages...

<?php $path = $_SERVER['SCRIPT_NAME']; ?>
<ul>
<li <?php if($path == $navHome) echo('id="current"') ?>><a href="/index.php">Home</a></li>
<li <?php if($path == $navInfo) echo('id="current"') ?>><a href="/lommiinfo/index.php">LOMMI Info</a></li>
<li <?php if($path == $navCal) echo('id="current"') ?>><a href="/calendar/index.php">Calendar</a></li>
<li <?php if($path == $navRes) echo('id="current"') ?>><a href="/resources/index.php">Resource Centre</a></li>
<li <?php if($path == $navArt) echo('id="current"') ?>><a href="/articles/index.php">Articles</a>
<li <?php if($path == $navMin) echo('id="current"') ?>><a href="/ministries/index.php">Ministries</a></li>
<li <?php if($path == $navLogin) echo('id="current"') ?>><a href="/logincentre/index.php">Login Centre</a></li>
<li <?php if($path == $navSite) echo('id="current"') ?>><a href="/sitemap/index.php">Site Map</a> </li>
</ul>

No, I've ran into another brick wall and that is when I log in there is some conditions to all uses to have access depending on user level. So in my admin section there is another include of menu navigation however, I have placed some conditions which you will see. I am wondering if the same process that is above can be used to this code below. Now, fiddled with it back and forth to see if it can work and it is struggling, so I was wondering if you or anyone is able to guide me.

Here is the code for a navigation menu that is being used in a <?php include'adminNav.php']; ?>...

<?php $path = $_SERVER['SCRIPT_NAME']; ?>
<ul>
<li <?php if($path == $adMain) echo('id="current"') ?>><a href="/logincentre/admin/index.php">Main</a></li>
<?php
if ($_SESSION['MM_UserGroup'] == 1 || $_SESSION['MM_UserGroup'] == 2 || $_SESSION['MM_UserGroup'] == 5)
echo '<li><a href="/logincentre/admin/pageEdit/index.php">Edit Webpages </a></li>';
else
echo '';
?>

<?php
if ($_SESSION['MM_UserGroup'] == 1)
echo '<li><a href="/logincentre/admin/adminControl/index.php">Admin</a></li>';
else
echo '';
?>

<li><a href="/logincentre/admin/logout.php">Logout</a></li>
</ul>