Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

PHP code for links with current state

Guest
Feb 28, 2007 Feb 28, 2007
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
TOPICS
Server side applications
515
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2007 Mar 01, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 01, 2007 Mar 01, 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2007 Mar 01, 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/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 02, 2007 Mar 02, 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>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2007 Mar 01, 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.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 01, 2007 Mar 01, 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.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 03, 2007 Mar 03, 2007
LATEST
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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines