Jump to content

Help with PHP menu


Icebergness

Recommended Posts

Hi,

 

I realise there is likely a very simple solution to this, but I'm pulling my hair out on it.

 

I have a menu.php file on my Intranet that (funnily enough) holds the site menu and is inserted via an include. This works fine. My question is, how can I make it pick up what page I am on in the site, and change the menu accordingly?

 

At the moment, with HTML (and before I changed the site to hold just one menu file), the menu looked like this:

 

<li class="link">
		<a class="link levela" title="The drive formally known as "P"">
		<span>Company Documents</span></a>
		<ul>
				<li class="link">
				<a class="link levelb" href="http://hhnet/company_documents/comm_forms.php" title="Forms... for Commission">
				<span>Commission Forms</span></a></li>

				<li class="link">
				<a class="link levelb" href="http://hhnet/company_documents/complaint_documentation.php" title="Documents documenting complaints.">
				<span>Complaint Documentation</span></a></li>

 

and when the page was the current one, it looked like this:

 

<li class="current">
		<a class="current levela" title="The drive formally known as "P"">
		<span>Company Documents</span></a>
		<ul>
				<li class="current">
				<a class="current levelb" href="http://hhnet/company_documents/comm_forms.php" title="Forms... for Commission">
				<span>Commission Forms</span></a></li>

				<li class="link">
				<a class="link levelb" href="http://hhnet/company_documents/complaint_documentation.php" title="Documents documenting complaints.">
				<span>Complaint Documentation</span></a></li>

 

As you can see, the class changes to "current". I want to be able to do it so that the central menu file can pick up what page the user is on, and mark the class as current.

 

Any suggestions?

 

Dave

Link to comment
Share on other sites

<?php

$path = $_SERVER['SCRIPT_NAME'];

$script = explode("/", $path);

$filename = explode(".", $script[sizeof($script) - 1]);

?>

 

<li class="link">

<a class="link levela" title="The drive formally known as "P"">

<span>Company Documents</span></a>

<ul>

<li class="link">

<a class="<?php if ($filename[0] == "comm_forms") { echo "current"; }else{ echo "link"; } ?> levelb" href="http://hhnet/company_documents/comm_forms.php" title="Forms... for Commission">

<span>Commission Forms</span></a></li>

 

<li class="link">

<a class="<?php if ($filename[0] == "complaint_documentation") { echo "current"; }else{ echo "link"; } ?> levelb" href="http://hhnet/company_documents/complaint_documentation.php" title="Documents documenting complaints.">

<span>Complaint Documentation</span></a></li>

Link to comment
Share on other sites

I would need to see the code for index.php, menu.php, and a sample content page to provide that level of information.  It will also likely requre a significant re-write of the code, not something that can be posted up in a hurry.  If the OP is prepared to provide the affore mentioned code I will happily have a look at what can be done.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.