howard-moore Posted February 15, 2013 Share Posted February 15, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/274519-adding-focus-to-a-dynamic-menu/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.