Page 1 of 2
td-menu replacement tag
Posted: Sat 29. Jan 2005, 18:03
by frold
Hey
Im looking for a replacement tag that output the sitestructure like this:
<tr>
<td class="topmenu">
<a href="" class="inactive">Option</a>
<a href="" class="active">Option</a>
<a href="" class="inactive">Option</a>
</td>
</tr>
<tr>
<td class="topmenusublevel">
<a href="" class="inactive">Suboption</a>
<a href="" class="inactive">Suboption</a>
<a href="" class="active">Suboption</a>
</td>
</tr>
Where you have the all toplevels menu items in one <TD> and the activated toplevel gets the class "active".
And then you have all the sublevels listed in another <TD> and the activated sublevel should also have the class activated..
can any one help?
do you understand?
Posted: Sat 29. Jan 2005, 18:47
by Oliver Georgi
use NAV_ROW in combination with top level check - such global level ID is included in coming dev release.
Oliver
Posted: Sat 29. Jan 2005, 19:18
by frold
Thank you for taking your time to help!!
use NAV_ROW in combination with top level check
Im do not understand?
but a very powerfull replacement tag would be:
{LEVEL:1} // would only list the first level and will always be shown
{LEVEL:2} // when pressed on level1, then level 2 is shown
{LEVEL:3} //when pressed on level 2 level 3 is showen etc...
With a menu like this:
Code: Select all
Level 1 //alias=level1
--sublevel 1.1 //alias=level11
----subsublevel 1.1.1 //alias=level111
Level 2 //alias=level2
On index.php the menu would look like this:
Level 1 | Level 2
On index.php?level11
Level 1 | Level 2
Sublevel .1.1
On index.php?level111
Level 1 | Level 2
Sublevel .1.1
Subsublevel 1.1.1
Maybe
http://www.frold.lir.dk/jopav2 illustrate it...
Posted: Sat 29. Jan 2005, 20:13
by frold
In some way this script does it...but I cannot fix it
I took the code from another script....
Place it in frontend_render
Code: Select all
<?
function frold_menu ($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_frold_menu ($struct, $level, $temp_tree, $act_cat_id, $nav_table_struct, $level_depth, $c, $link_to); //starts at root level
return ($temp_menu) ? ($temp_menu) : "";
}
// -------------------------------------------------------------
function build_frold_menu ($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;
$colspan = ($depth2 > 1) ? " colspan=\"".$depth2."\"" : "";
$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 = $link_to."?id=".$key.",0,0,1,0,0";
if($temp_tree[$key]) {
if($act_cat_id == $key) {
$temp_menu .= "<a class=\"active\" href=\"".$link."\">active_1".html_specialchars($struct[$key]["acat_name"])."</a>\n";
} else {
$temp_menu .= "<a class=\"active\" href=\"".$link."\">active_2".html_specialchars($struct[$key]["acat_name"])."</a>\n";
}
$temp_menu .= build_frold_menu ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to);
} else {
//inactive menupunkter f.eks. når hovedsiden loades == index.php
$temp_menu .= "<a class=\"inactive\" href=\"".$link."\">".html_specialchars($struct[$key]["acat_name"])."</a>\n";
}
}
}
$temp_menu .= "";
if($nav_table_struct["row_space"] && $count == 1) $temp_menu .= $space_row;
$temp_menu1 .= "</table>";
return $temp_menu;
}
if( ! ( strpos($content["all"],'{FROLD')===false ) ) {
$content["all"] = str_replace('{FROLD}', '{FROLD:0}', $content["all"]);
$replace = 'frold_menu($content["struct"],intval($content["cat_id"]),"$1",$template_default["nav_table_struct"]);';
$content["all"] = preg_replace('/\{FROLD:(\d+)\}/e', $replace, $content["all"]);
}
?>
It works at the toplevel but when it doesnt work anymore because toplevel and sublevel links are mixed... I need first all toplevel listed and then sublevel....
Posted: Sat 29. Jan 2005, 20:38
by frold
I try to explain it more simple
What I need is a tag that output just
Toplevel
and another on that output just
Sublevel
basted on toplevel, if a toplevel is choosed
and so on...
Posted: Sat 29. Jan 2005, 21:16
by Oliver Georgi
place this around line 80 in content.func.inc.php
Code: Select all
$LEVEL_ID = array();
$level_ID_array = get_breadcrumb($content["cat_id"], $content['struct']);
if(is_array($level_ID_array) && count($level_ID_array)) {
$level_count = 0;
foreach($level_ID_array as $key => $value) {
$LEVEL_ID[$level_count] = $key;
$level_count++;
}
unset($level_ID_array);
}
You can place following code for testing after that part of code and you will understand - to have access on structure use
$content["struct"]:
Code: Select all
echo '<pre>';
print_r($LEVEL_ID);
print_r($content['struct']);
echo '</pre>';
Oliver
Posted: Sat 29. Jan 2005, 21:51
by frold
Oliver Georgi wrote:place this around line 80 in content.func.inc.php
Code: Select all
$LEVEL_ID = array();
$level_ID_array = get_breadcrumb($content["cat_id"], $content['struct']);
if(is_array($level_ID_array) && count($level_ID_array)) {
$level_count = 0;
foreach($level_ID_array as $key => $value) {
$LEVEL_ID[$level_count] = $key;
$level_count++;
}
unset($level_ID_array);
}
You can place following code for testing after that part of code and you will understand - to have access on structure use
$content["struct"]:
Code: Select all
echo '<pre>';
print_r($LEVEL_ID);
print_r($content['struct']);
echo '</pre>';
Oliver
sorry it doesnt help my stupid brain much....
Posted: Sat 29. Jan 2005, 22:29
by Oliver Georgi
It will look like this:
Where [INT] represents current level -> [0] = TOP LEVEL, [1] is level under [0]. The number (INT) behind represents ID of that level.
Then compare the result of
against these IDs.
?
Oliver
Posted: Sun 30. Jan 2005, 00:27
by frold
sorry it doesnt help me....
I dont understand the "loops" the script make in:
function frold_menu:
If I have this menu:
Level 1 //alias=level1
--sublevel 1.1 //alias=level11
Level 2 //alias=level2
Level 3
And press on sublevel 1.1 the script list:
Level 1 | Sublevel 1.1 | Level 2
I want it to eg list it like this:
Level 1 | Level 2 | Level 3 | Subelevel 2.1
If I press
Sublevels should first be listed at the end... But I can't figure out howto control that....
I guess it is this code snip that does it?
Code: Select all
if($temp_tree[$key]) {
if($act_cat_id == $key) {
//når toplevel er aktivt eller
$temp_menu .= "<a class=\"active\" href=\"".$link."\">active_1".html_specialchars($struct[$key]["acat_name"])."</a>\n";
} else {
$temp_menu .= "<a class=\"active\" href=\"".$link."\">active_2".html_specialchars($struct[$key]["acat_name"])."</a>\n";
}
$temp_menu .= build_frold_menu ($struct, $key, $temp_tree, $act_cat_id, $nav_table_struct, $count, $div, $link_to);
} else {
$temp_menu .= "<a class=\"inactive\" href=\"".$link."\">".html_specialchars($struct[$key]["acat_name"])."</a>\n";
}
Posted: Sun 30. Jan 2005, 14:51
by Oliver Georgi
Try this - copy whole code in a file (i.e. sublevelnav.php) which has to be placed in
phpwcms_template/inc_script/frontend_render and use
{MY_LEVEL_NAV} as replacement tag for that menu:
Code: Select all
<?php
if( ! ( strpos($content["all"],'{MY_LEVEL_NAV}')===false ) ) {
$complexNav = '';
// equal template_defaults for all NAV_ROW
// don't forget to use $GLOBALS when using this in function
// like: $GLOBALS['template_default']["nav_row"]["after"]
// and : $GLOBALS['LEVEL_ID']
$template_default["nav_row"]["after"] = '</ul>';
$template_default["nav_row"]["between"] = "\n";
$template_default["nav_row"]["link_before"] = '<li class="inactive">';
$template_default["nav_row"]["link_after"] = '</li>';
$template_default["nav_row"]["link_before_active"] = '<li class="active">';
$template_default["nav_row"]["link_after_active"] = '</li>';
$template_default["nav_row"]["link_direct_before"] = '';
$template_default["nav_row"]["link_direct_after"] = '';
$template_default["nav_row"]["link_direct_before_active"] = '';
$template_default["nav_row"]["link_direct_after_active"] = '';
foreach($LEVEL_ID as $depth => $thisStructureID) {
switch($depth) {
case 0: // Top Level
$template_default["nav_row"]["before"] = '<ul class="levelClass0">';
$complexNav .= nav_level_row($thisStructureID,0);
break;
case 1: // 1st Level
$template_default["nav_row"]["before"] = '<ul class="levelClass1">';
$complexNav .= nav_level_row($thisStructureID,0);
break;
case 2: // 2nd Level
$template_default["nav_row"]["before"] = '<ul class="levelClass2">';
$complexNav .= nav_level_row($thisStructureID,0);
break;
case 3: // 3rd Level
$template_default["nav_row"]["before"] = '<ul class="levelClass3">';
$complexNav .= nav_level_row($thisStructureID,0);
break;
case 4: // 4th Level
$template_default["nav_row"]["before"] = '<ul class="levelClass4">';
$complexNav .= nav_level_row($thisStructureID,0);
break;
}
}
$content["all"] = str_replace('{MY_LEVEL_NAV}', $complexNav, $content["all"]);
}
?>
You can enhance the switch section for as many levels you need.
Oliver
Posted: Sun 30. Jan 2005, 17:05
by frold
wauw.... you are a sweethard...!!
It works like a charm...
It gives you totally new ways to make menus
so brilliant...!!!
Posted: Sun 30. Jan 2005, 17:19
by cyrano
hi frold,
what does it means with this:
// equal template_defaults for all NAV_ROW
// don't forget to use $GLOBALS when using this in function
// like: $GLOBALS['template_default']["nav_row"]["after"]
// and : $GLOBALS['LEVEL_ID']
I copied the code and place it in frontend_render folder and named it sublevel.php, but got an error shown means line 22...
I have set allow_remote_URL to "1"
do i have to do more?
Thank you for advice.
Posted: Sun 30. Jan 2005, 17:23
by frold
cyrano wrote:hi frold,
what does it means with this:
// equal template_defaults for all NAV_ROW
// don't forget to use $GLOBALS when using this in function
// like: $GLOBALS['template_default']["nav_row"]["after"]
// and : $GLOBALS['LEVEL_ID']
I copied the code and place it in frontend_render folder and named it sublevel.php, but got an error shown means line 22...
I have set allow_remote_URL to "1"
do i have to do more?
Thank you for advice.
yep allow render....
71 $phpwcms["allow_ext_init"] = 0;
This function allows you to load your own PHP scripts before phpWCMS is loaded.
Your files are stored in the following directory.
/phpwcms_template/inc_script/frontend_init
Default = 0 Forbidden / 1 = Allowed.
72 $phpwcms["allow_ext_render"] = 0;
If you use existing functions from the INIT folder for rendering the page.
These files can be rendered from the directory
/phpwcms_template/inc_script/frontend_render
Default = 0 Forbidden / 1 = Allowed
Posted: Sun 30. Jan 2005, 17:27
by cyrano
hi frold,
thank you for your fast reply.
I know to set both to "1", that is made.
I put the line {MY_LEVEL_NAV} into my templates left field and open the url in frontend and got an error.
Do i need to change the naming of {MY_LEVEL_NAV}?
Posted: Sun 30. Jan 2005, 17:41
by Oliver Georgi