Jump to content

Adding focus to a dynamic menu


howard-moore

Recommended Posts

Hi,

 

I have put together the following script which creates a dynamic drop-menu (in unordered list which is subsequently styled in CSS). What I am looking to do is find a way to add a focus to show the menu tab in a different colour when that page has been selected.

 

Currently the below PHP is called on each page of the website. It is done like this to have top-level pages (parent pages) and sub-pages, and is ordered by a page order (both top-level and sub-page). All the pages on the website has a unique field called 'code', and in the past I have used class="there" in the unordered list item when that code has been selected, but I really don't know how I can do it with the below code:

 

<?php
$result=mysql_query("SELECT id, title, link, parent_code, page_order, menu_title, parent_live, parent_title, page_type, live, FROM PCNET_$filename WHERE type='PAGE' AND live='checked' ORDER BY parent_code, page_order, title");
$menu = array(
   'items' => array(),
   'parents' => array()
);
while ($items = mysql_fetch_assoc($result))
{
   $menu['items'][$items['id']] = $items;
   $menu['parents'][$items['parent_code']][] = $items['id'];
}
function buildMenu($parent_code, $menu)
{
  $html = "";
  if (isset($menu['parents'][$parent_code]))
  {
  $html .= "\n";
   foreach ($menu['parents'][$parent_code] as $itemId)
   {
	  if(!isset($menu['parents'][$itemId]))
	  {
		 $html .=  "<li><a href=\"".$menu['items'][$itemId]['link']."?eid=".$menu['items'][$itemId]['id']."\">".$menu['items'][$itemId]['menu_title']."</a></li>";
	  }
   $html .= "\n";
	  if(isset($menu['parents'][$itemId]))
	  {
		 $html .=  "<li><a href=\"".$menu['items'][$itemId]['link']."?eid=".$menu['items'][$itemId]['id']."\">".$menu['items'][$itemId]['menu_title']."</a><ul>";
		 $html .= buildMenu($itemId, $menu);
	  }
   }
   $html .= "</ul></a></li> \n";
  }
  return $html;
}
echo buildMenu(0, $menu);
?>

 

This is what I have used in the past (when the above menu code was static, and not the new dynamic version) to show when a page has been selected:

 

<li<?php if ($code == 'local-info') echo ' class="there"'; ?>>

 

If anyone has any suggestions how I can get the class="there" into the above when you are on a particular page I would really appreciate the feedback - been tearing my hair out over this one for days!

 

 

Thanks,

Neil

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.