I found something that works concerning your idea. can be improved though. I'm a php beginner. yippi.rtilghman wrote:
What I would like to do is have the ability to have the parent item "active" when a child area is selected... which would make a lot more sense. So, for example, if you had a menu with 5 top links (visible) andthe user was in a page that resides in the pathway of "link 1" link 1 would have the ACTIVE class so you could have it highlighted.
Code: Select all
<?php
function build_dhtmlmenu2($start=0, $class='', $activeclass='', $counter=0) {
// **************************************************************************
// Paul: nice HTML source format, from class='classname' to class="classname"
$class="class="".$class.""";
$classactive="class="".$activeclass.""";
// Paul: nice HTML source format END
// **************************************************************************
$s = '';
$g = '';
// **************************************************************************
// Paul: for submenu
$thfs = $GLOBALS["content"]["struct"];
foreach($thfs as $key => $value)
{
$x = &$GLOBALS["content"]["struct"][$value["acat_struct"]];
if($value["acat_struct"] != 0)
$x["acat_has_children"] = 1;
else
$x["acat_has_children"] = 0;
}
// Paul: for submenu END
// **************************************************************************
// **************************************************************************
// Hendrik: 3 level
$bef0 = $GLOBALS['aktion'][0];
$bef1 = $GLOBALS['content']['struct'][$bef0]['acat_struct'];
$bef2 = $GLOBALS['content']['struct'][$bef1]['acat_struct'];
// Hendrik: 3 level END
// **************************************************************************
foreach($GLOBALS['content']['struct'] as $key => $value) {
if ($start == $GLOBALS['content']['struct'][$key]['acat_struct'] &&
!$GLOBALS['content']['struct'][$key]['acat_hidden'] && $key)
{
$s .= '<li';
// **************************************************************************
// Hendrik: change and add
if($key == $bef0 && $activeclass) $s .= ' '.$classactive;
if($key == $bef1 && $activeclass) $s .= ' '.$classactive;
if($key == $bef2 && $activeclass) $s .= ' '.$classactive;
// Hendrik: change and add END
// **************************************************************************
$s .= '>';
if(!$GLOBALS['content']['struct'][$key]["acat_redirect"]) {
$s .= '<a href="index.php?';
if($GLOBALS['content']['struct'][$key]['acat_alias']) {
$s .= $GLOBALS['content']['struct'][$key]['acat_alias'];
} else {
$s .= 'id='.$key.',0,0,1,0,0';
}
// **************************************************************************
// Paul: change and add
$s .= '"';
if($GLOBALS['content']['struct'][$key]['acat_has_children'])
$s .= ' class="submenu"';
$s .= '>';
// Paul: change and add END
// **************************************************************************
} else {
$redirect = get_redirect_link($GLOBALS['content']['struct'][$key]["acat_redirect"], ' ', '');
$s .= '<a href="'.$redirect['link'].'"'.$redirect['target'].'>';
}
$s .= html_specialchars($GLOBALS['content']['struct'][$key]['acat_name']);
$s .= '</a>';
$s .= build_dhtmlmenu2($key, $class, $activeclass,$counter+1);
$s .= "</li>\n";
}
}
if($s) {
$g = "\n<ul";
if(!$counter && $class) {
$g .= ' '.$class;
}
$g .= ">\n".$s.'</ul>';
}
return $g;
}
// parse the whole webpage $content["all"] is the fully rendered webpage your site displays
$content["all"] = (myTagParser ($content["all"]));
// parse the $string and replace all possible instances of the following {RT}'s
function myTagParser($string) {
$search[0] = '/\{DHTMLMENU:(.*?),(.*?),(.*?)\}/e';
$replace[0] = 'build_dhtmlmenu2("$1","$2","$3");';
$string = preg_replace($search, $replace, $string);
$string = str_replace('\'', '\'',$string);
$string = str_replace('"', '"',$string);
return $string; // spit out the final webpage for display
}
?>