{NAV_LIST_ALL} using UL und LI
Posted: Thu 2. Mar 2006, 08:28
Hi,
I want to use the {NAV_LIST_ALL} replacement tag with UL and LI and not DIV. So I inserted the code posted on April 2004 (first version of this reptag) into reptag_ccs_nav_list_all.php:
The problem is, that the UL und LI nesting is not always displayed properly:
If the active page is in the first level, everything is OK:
But if the active page is in a sublevel, a wrong </LI> is inserted before the second UL:
How must the PHP-code be modified to get a correct nesting?
Thanks,
missberli
I want to use the {NAV_LIST_ALL} replacement tag with UL and LI and not DIV. So I inserted the code posted on April 2004 (first version of this reptag) into reptag_ccs_nav_list_all.php:
Code: Select all
<?php
// -------------------------------------------------------------
// css nav {NAV_LIST_ALL} using <ul> and <li> tags
// -------------------------------------------------------------
function css_list_all ($struct, $act_cat_id, $level, $nav_table_struct, $link_to="index.php") {
// start with home directory for the listing = top nav structure
// 1. Build the recursive tree for given actual article category ID
// return the tree starting with given start_id (like breadcrumb)
// if the $start_id = 0 then this stops because 0 = top level
$level = intval($level);
$start_id = $act_cat_id;
while ($start_id) {
$data[$start_id] = 1;
$start_id = $struct[$start_id]["acat_struct"];
}
$temp_tree = (sizeof($data)) ? array_reverse($data, 1) : false;
foreach($struct as $key => $value) {
if($struct[$key]["acat_struct"] == $act_cat_id && $key && !$struct[$key]["acat_hidden"]) $c++;
}
$c = (!$c) ? 1 : 0;
//get depth of level
$level_depth = 0; $start_level = $level;
while ($start_level) {
$start_level = $struct[$start_level]["acat_struct"];
$level_depth++;
}
$temp_menu = build_levels_list ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $level_depth, $c, $link_to); //starts at root level
return ($temp_menu) ? ("\n<ul class=\"navList\">".$temp_menu."</ul>\n") : "";
}
//----------------------------------------------------------------------------
function build_levels_list ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to) {
// this returns the level structure based on given arrays
// it is special for browsing from root levels
$depth = sizeof($temp_tree)-$div; $count++; $depth2 = $depth-$count+2;
$temp_menu = "";
foreach($struct as $key => $value) {
if($_SESSION["frontend_user_in"] && $struct[$key]["acat_regonly"]) $struct[$key]["acat_regonly"] = 0;
if($struct[$key]["acat_struct"] == $level && $key && !$struct[$key]["acat_hidden"] && !$struct[$key]["acat_regonly"]) {
$link_image_id = "linkid".randpassword(6);
$link_name_id = ' name="'.$link_image_id.'" id="'.$link_image_id.'"';
$link = $link_to."?";
$link .= ($struct[$key]["acat_alias"]) ? html_specialchars($struct[$key]["acat_alias"]) : 'id='.$key.',0,0,1,0,0';
if($temp_tree[$key]) {
if($act_cat_id == $key) {
//If we need nesting:
$temp_menu .= "<li class=\"MenuItem_lvl_".$count."\" id=\"activeSection\"><a href=\"".$link."\">".html_specialchars($struct[$key]["acat_name"])."</a>";
//no nesting
//$temp_menu .= "<li class=\"MenuItem_lvl_".$count."\" id=\"activeSection\"><a href=\"".$link."\">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
} else {
$temp_menu .= "<li class=\"MenuItem_lvl_".$count."\"><a href=\"".$link."\">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
}
//If we need nesting:
//check to see if there are any subitems for this item
if(build_levels_list ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to)!=""){
//subitems: open a new <ul>
$temp_menu .= "\n<ul>\n";
$temp_menu .= build_levels_list ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to);
$temp_menu .= "</ul>\n</li>\n";
}
else {
//no subitems: close the <li>
$temp_menu .= "</li>\n";
}
// No nesting
//$temp_menu .= build_levels_list ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to);
} else {
$temp_menu .= "<li class=\"MenuItem_lvl_".$count."\"><a href=\"".$link."\">".html_specialchars($struct[$key]["acat_name"])."</a></li>\n";
}
}
}
return $temp_menu;
}
// -------------------------------------------------------------
// <ul>-list based Navigation table
if( ! ( strpos($content["all"],'{NAV_LIST_ALL')==false ) ) {
$content["all"] = str_replace('{NAV_LIST_ALL}','{NAV_LIST_ALL:0}',$content["all"]);
$replace = 'css_list_all($content["struct"],intval($content["cat_id"]),"$1",$template_default["nav_table_struct"]);';
$content["all"] = preg_replace('/\{NAV_LIST_ALL:(\d+)\}/e', $replace, $content["all"]);
}
?>
If the active page is in the first level, everything is OK:
Code: Select all
<ul class="navList">
<li class="MenuItem_lvl_1"><a href="">Home</a></li>
<li class="MenuItem_lvl_1" id="activeSection"><a href="">page 1</a>
<ul>
<li class="MenuItem_lvl_2"><a href="">page 1.1</a></li>
<li class="MenuItem_lvl_2"><a href="">page 1.2</a></li>
</ul>
</li>
<li class="MenuItem_lvl_1"><a href="">page 2</a></li>
</ul>
Code: Select all
<ul class="navList">
<li class="MenuItem_lvl_1"><a href="">Home</a></li>
<li class="MenuItem_lvl_1"><a href="">page 1</a></li>
<ul>
<li class="MenuItem_lvl_2" id="activeSection"><a href="">page 1.1</a></li>
<li class="MenuItem_lvl_2"><a href="">page 1.2</a></li>
</ul>
</li>
<li class="MenuItem_lvl_1"><a href="">page 2</a></li>
</ul>
Thanks,
missberli