rtilghman wrote:This is the working RT code. Copy this to a file in "phpwcms_template\inc_script\frontend_render" with a proper name to use it.
I use this function, for submenu:
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
// **************************************************************************
foreach($GLOBALS['content']['struct'] as $key => $value) {
if ($start == $GLOBALS['content']['struct'][$key]['acat_struct'] &&
!$GLOBALS['content']['struct'][$key]['acat_hidden'] && $key)
{
$s .= '<li';
if($key == $GLOBALS['aktion'][0] && $activeclass) $s .= ' '.$classactive;
$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
}
?>
Add to CSS:
Code: Select all
#primaryNav ul ul li a.submenu {
background-image: url(../../picture/arrowWhite.gif);
background-repeat: no-repeat;
background-position: 100% .4em;
padding-right: .6em;
}
The source:
Original:
Code: Select all
<div id='primaryNav'>
<ul class='itemOff'>
<li><a href="#">Menu 1</a>
<ul>
<li class='itemOn'><a href="#">Menu 1,1</a></li>
<li><a href="#">Menu 1,2</a>
<ul>
<li><a href="#">Menu 1,2,1</a></li>
<li><a href="#">Menu 1,2,2</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
<li><a href="#">Menu 4</a></li>
</ul>
</div>
The new:
Code: Select all
<div id="primaryNav">
<ul class="itemOff">
<li><a href="#" class="submenu">Menu 1</a>
<ul>
<li class="itemOn"><a href="#">Menu 1,1</a></li>
<li><a href="#" class="submenu">Menu 1,2</a>
<ul>
<li><a href="#">Menu 1,2,1</a></li>
<li><a href="#">Menu 1,2,2</a></li>
</ul>
</li>
</ul>
</li>
<li><a href="#">Menu 2</a></li>
<li><a href="#">Menu 3</a></li>
<li><a href="#">Menu 4</a></li>
</ul>
</div>
The result
(UPDATED!):
Selected menuitem: Menu2,3
Menu has children/submenu: Menu2,2 (+ hover)
Demo link:
http://www.fishmania.hu/demo.html
Paul