made a small reptag, called {NAV_STRUCT}.
You can:
- define the start-level (all, auto, alias)
- define expand all or only the active level
- add a style
Maybe it looks like the NAV_TABLE_COLUMN, but without javascript and complete with css-lists. Tested with 1.2.6 and with a alias for every menu.
(I only work with aliases...)
You also can use this for sitemaps.
Last Update: 16.03.2006, 14:30
- changed some code for valid html
- add new option => $active_parent, 0 or 1, you can decide, if the parent menu is marked as active or not
Download:
http://spielwiese.wireframe.de
Code: Select all
<?php
// parameter(4): {NAV_STRUCT:$start_level_name:$auto_start_level:$menu_expand:$active_parent:$style}
// $start_level_name: auto=>shows struct from act level, 0=>shows complete struct, string=>shows struct from this level
// $auto_start_level: startlevel from which menus are shown. only if $start_level_name <> 0, number=>number of startlevel >=0
// $menu_expand: expand all menus or not. 0=>no, 1>=yes. if yes, all id`s (ul, li, a) are changed in classes
// $active_parent: if $menu_expand=1, mark active parent menu as active. 0=>no, 1>=yes
// $style: name of style. string=>style name
// always write 0 for unused parameters
// example: {NAV_STRUCT:auto:2:0:1:myStyle}
// standard (for starting and testing or sitemap): {NAV_STRUCT:0:0:1:0:naviStruct}
// installation: make a file ("reptag_nav_struct.php") in "phpwcms_template\inc_script\frontend_render" and copy the script in the file
// Andi Platen, 16.03.2006, www.wireframe.de|www.gleitschirm-taxi.de|www.mountain-panorama.com
// -------------------------------------------------------------
function css_nav_struct($start_level_name="", $auto_start_level="", $menu_expand="", $active_parent="", $style="")
{
$start_level_name = trim($start_level_name);
$real_start_level_name = $start_level_name;
$GLOBALS['auto_start_level'] = intval($auto_start_level);
$GLOBALS['menu_expand'] = intval($menu_expand);
$GLOBALS['active_parent'] = intval($active_parent);
$GLOBALS['style'] = trim($style);
$breadcrumb = get_navi_struct_breadcrumb($GLOBALS['content']["cat_id"], $GLOBALS['content']['struct']);
$breadcrumb = implode("§§", $breadcrumb);
$breadcrumb = explode("§§", $breadcrumb);
$GLOBALS['breadkrempel'] = $breadcrumb;
if($start_level_name == 'auto')
{
$counter_start = $auto_start_level - 1;
$start_level_name = $breadcrumb[$GLOBALS['auto_start_level']];
}
else if($start_level_name == '0')
{
$GLOBALS['auto_start_level'] = 0;
$counter_start = $GLOBALS['auto_start_level'];
$start_level_name = $GLOBALS['content']["struct"][0]['acat_alias'];
}
else
{
$GLOBALS['auto_start_level'] = 0;
$counter_start = $GLOBALS['auto_start_level'];
$counter_start = 0;
}
foreach($GLOBALS['content']["struct"] as $key => $value)
{
if($GLOBALS['content']["struct"][$key]['acat_alias'] == $start_level_name)
{
$start_level_name = $GLOBALS['content']["struct"][$key]['acat_id'];
$start_name = $GLOBALS['content']["struct"][$key]['acat_name'];
$start_alias = $GLOBALS['content']["struct"][$key]['acat_alias'];
break;
}
}
$s = make_struct($start_level_name, $counter_start);
if($real_start_level_name == '0')
{
if($start_alias == $GLOBALS['content']['struct'][$GLOBALS['content']['cat_id']]['acat_alias'])
{
$mystart = '<a id="' . $GLOBALS['style'] . '_current" href="index.php?' . $start_alias . '">' . $start_name . '</a>';
$s = '<ul id="' . $GLOBALS['style'] . '_0_ul">' . "\n" . '<li id="' . $GLOBALS['style'] . '_active">' . $mystart . '</li>' . $s . '</ul>';
}
else if($GLOBALS['active_parent'] == '1')
{
$mystart = '<a id="' . $GLOBALS['style'] . '_current_0" href="index.php?' . $start_alias . '">' . $start_name . '</a>';
$s = '<ul id="' . $GLOBALS['style'] . '_0_ul">' . "\n" . '<li id="' . $GLOBALS['style'] . '_0_active">' . $mystart . '</li>' . $s . '</ul>';
}
else
{
$mystart = '<a href="index.php?' . $start_alias . '">' . $start_name . '</a>';
$s = '<ul id="' . $GLOBALS['style'] . '_0_ul">' . "\n" . '<li>' . $mystart . '</li>' . $s . '</ul>';
}
}
if($s)
{
$s = '<div id="' . $GLOBALS['style'] . '">' . "\n" . $s . "\n" . '</div>';
}
$s = ereg_replace("</li><li", "</li>\n<li", $s);
$s = ereg_replace("</li></ul>", "</li>\n</ul>", $s);
$s = ereg_replace("</li><ul", "\n<ul", $s);
$s = ereg_replace("</ul><li", "</ul></li>\n<li", $s);
if($GLOBALS['menu_expand'] == '1')
{
$s = ereg_replace("<ul id", "<ul class", $s);
$s = ereg_replace("<li id", "<li class", $s);
$s = ereg_replace("<a id", "<a class", $s);
}
return $s;
}
// -------------------------------------------------------------
// -------------------------------------------------------------
function make_struct($start=0, $counter=0)
{
$counter++;
$act_cat = $GLOBALS['content']['struct'][$GLOBALS['content']['cat_id']]['acat_alias'];
foreach($GLOBALS['content']['struct'] as $key => $value)
{
if($start == $GLOBALS['content']['struct'][$key]['acat_struct'] && $key && !$GLOBALS['content']['struct'][$key]['acat_hidden'])
{
if($GLOBALS['content']['struct'][$key]['acat_redirect'] != "")
{
$link = $GLOBALS['content']['struct'][$key]['acat_redirect'];
}
else
{
$link = "index.php?" . $GLOBALS['content']['struct'][$key]['acat_alias'];
}
if($GLOBALS['content']['struct'][$key]['acat_alias'] == $act_cat)
{
$s .= '<li id="' . $GLOBALS['style'] . '_active">';
}
else
{
$s .= '<li>';
}
if($GLOBALS['content']['struct'][$key]['acat_alias'] == $act_cat)
{
$s .= '<a id="' . $GLOBALS['style'] . '_current" href="' . $link . '">' . $GLOBALS['content']['struct'][$key]['acat_name'] . '</a>';
}
else
{
$s .= '<a href="' . $link . '">' . $GLOBALS['content']['struct'][$key]['acat_name'] . '</a>';
}
$s .= '</li>';
if($GLOBALS['menu_expand'] == 0)
{
foreach($GLOBALS['breadkrempel'] as $a => $b)
{
foreach($GLOBALS['content']["struct"] as $c => $d)
{
if($b == $GLOBALS['content']["struct"][$c]['acat_alias'])
{
$breadcrumb_parent[] = $GLOBALS['content']["struct"][$c]['acat_struct'];
}
}
}
if($act_cat == $GLOBALS['content']['struct'][$key]['acat_alias'])
{
$s .= make_struct($key, $counter);
}
else if($key == $GLOBALS['content']['struct'][$GLOBALS['content']['cat_id']]['acat_struct'])
{
if($GLOBALS['active_parent'] == '1')
{
$alt = '<li><a href="' . $link . '">' . $GLOBALS['content']['struct'][$key]['acat_name'] . '</a></li>';
$neu = '<li id="' . $GLOBALS['style'] . '_' . $counter . '_active"><a id="' . $GLOBALS['style'] . '_current_' . $counter . '" href="' . $link . '">' . $GLOBALS['content']['struct'][$key]['acat_name'] . '</a></li>';
$s = str_replace($alt, $neu, $s);
}
$s .= make_struct($key, $counter);
}
else if(array_search($key, $breadcrumb_parent))
{
$z = array_search($key, $breadcrumb_parent);
$z = $breadcrumb_parent[$z];
if($GLOBALS['active_parent'] == '1')
{
$alt = '<li><a href="' . $link . '">' . $GLOBALS['content']['struct'][$key]['acat_name'] . '</a></li>';
$neu = '<li id="' . $GLOBALS['style'] . '_' . $counter . '_active"><a id="' . $GLOBALS['style'] . '_current_' . $counter . '" href="' . $link . '">' . $GLOBALS['content']['struct'][$key]['acat_name'] . '</a></li>';
$s = str_replace($alt, $neu, $s);
}
$s .= make_struct($z, $counter);
}
}
else
{
if($GLOBALS['active_parent'] == '1' && in_array($GLOBALS['content']['struct'][$key]['acat_alias'], $GLOBALS['breadkrempel']))
{
$alt = '<li><a href="' . $link . '">' . $GLOBALS['content']['struct'][$key]['acat_name'] . '</a></li>';
$neu = '<li id="' . $GLOBALS['style'] . '_' . $counter . '_active"><a id="' . $GLOBALS['style'] . '_current_' . $counter . '" href="' . $link . '">' . $GLOBALS['content']['struct'][$key]['acat_name'] . '</a></li>';
$s = str_replace($alt, $neu, $s);
}
$s .= make_struct($key, $counter);
}
}
}
if($s)
{
$s = '<ul id="' . $GLOBALS['style'] . '_' . $counter . '_ul">' . "\n" . $s . '</ul>';
}
return $s;
}
// -------------------------------------------------------------
// -------------------------------------------------------------
function get_navi_struct_breadcrumb($start_id, $struct_array)
{
$data = array();
while ($start_id)
{
$data[$start_id] = $struct_array[$start_id]["acat_alias"];
$start_id = $struct_array[$start_id]["acat_struct"];
}
if(!empty($struct_array[$start_id]["acat_alias"]))
{
$data[$start_id] = $struct_array[$start_id]["acat_alias"];
}
return array_reverse($data, 1);
}
// -------------------------------------------------------------
// -------------------------------------------------------------
if(!( strpos($content["all"],'{NAV_STRUCT')===false ) )
{
$content["all"] = preg_replace('/\{NAV_STRUCT:(.*?):(.*?):(.*?):(.*?):(.*?)\}/e', 'css_nav_struct("$1","$2","$3","$4","$5")', $content["all"]);
}
// -------------------------------------------------------------
?>
And here a example style for a sub-menu with 2 structure-levels:
Code: Select all
#naviStruct
{
margin: 0px;
padding: 0px 0px 0px 0px;
width: 100%;
border-bottom: dashed 1px #999999;
}
#naviStruct ul
{
margin: 0px;
padding: 0px;
list-style-type: none;
}
#naviStruct ul a
{
display: block;
padding: 2px 0px 2px 20px;
width: 100%;
text-decoration: none;
border-top: dashed 1px #999999;
background-image: url(../../stuff/images/diverse/arrow_1.gif);
background-repeat: no-repeat;
background-position: 10px 6px;
}
#naviStruct ul ul a
{
display: block;
padding: 2px 0px 2px 31px;
width: 100%;
text-decoration: none;
background-image: url(../../stuff/images/diverse/arrow_2.gif);
background-repeat: no-repeat;
background-position: 21px 7px;
}
#naviStruct a:link, #naviStruct a:visited
{
color: #999999;
font-weight: bold;
text-decoration: none;
}
#naviStruct a:hover
{
color: #000000;
}
#naviStruct_1_active a:link#naviStruct_current_1, #naviStruct_1_active a:visited#naviStruct_current_1, #naviStruct_1_active a:hover#naviStruct_current_1, #naviStruct_1_active a:active#naviStruct_current_1
{
color: #000000;
}
#naviStruct_active a:link#naviStruct_current, #naviStruct_active a:visited#naviStruct_current, #naviStruct_active a:hover#naviStruct_current, #naviStruct_active a:active#naviStruct_current
{
color: #000000;
}
Grüzli - Andi