{NAV_ANY_LEVEL} - Another Navigation RT With Many Options

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
wingover
Posts: 58
Joined: Wed 13. Apr 2005, 13:18
Contact:

{NAV_ANY_LEVEL} - Another Navigation RT With Many Options

Post by wingover »

Hi,

I have "bastelt" a navigation-tag with the following features:
- show only one menu level you want to see
- auto startlevel > shows sublevels. you can write startlevel and level count
- link to parent menu, yes or no, name of parent or diffrent name
- hide one ore more menus
- one style for navigation-tag or for every menu
- special style for active link and for back link
- separator between menus

I hope there are not so much mistakes in the script but I have tested and everything was working...

Latest Update: 15.03.2006, 22:30
- changed some code for valid html
- The active Link has now a 'id=current'
- I added a new parameter ($xtra_menu_style). It can be 0 or 1. When 1 and $start_level_name = 0 (auto), the "div" and "ul" "active" tag of every sub menu get a extra style (style name = $style + alias from parent menu). So it`s possible, that a dynamic sub menu can change the color or anything else depending from the parent menu.

Code: Select all

<?php

// parameter(9): {NAV_ANY_LEVEL:$start_level_name:$auto_start_level:$auto_level_depth:$back_link:$hide_level:$style:$xtra_menu_style:$xtra_li_style:$separator}
// $start_level_name: name of parent menu, 0=>auto, shows act level, string=>alias of parent menu
// $auto_start_level: startlevel from which menus are shown. only if $start_level_name <> 0, number=>number of startlevel >=0
// $auto_level_depth: count of shown levels starting from $auto_start_level. only if $start_level_name <> 0, number=>number of levels to show >=0
// $back_link: link to parent menu. only if $start_level_name <> 0, 0=>no link, 1=>link name is name of parent menu, string=>different name
// $hide_level: menus to hide. if more, separete with ",". 0=>no hidden menus, string=>alias of menus to hide
// $style: name of style for div,ul,li. string=>style name
// $xtra_menu_style: every menu (div, ul) get a style. only if $start_level_name <> 0, $style + alias of parent menu. 0=>no, 1=>yes
// $xtra_li_style: every "li" get a style. $style + alias of menu. 0=>no, 1=>yes
// $separator: separator between menus. 0=>no, string=>separator
// always write 0 for unused parameters
// style from active menu: $style + _active
// style from link to parent menu: $style + _back
// example: {NAV_ANY_LEVEL:mynavi:2:1:back:0:mystyle:0:0:|}
// standard (for starting and testing): {NAV_ANY_LEVEL:0:0:0:0:0:any_navi:0:0:0}
// installation: make a file ("reptag_nav_any_level.php") in "phpwcms_template\inc_script\frontend_render" and copy the script in the file
// Andi Platen, 07.03.2006, www.wireframe.de|www.gleitschirm-taxi.de|www.mountain-panorama.com



// -------------------------------------------------------------
function get_navi_struct($catID, $start_level_name, $auto_start_level, $auto_level_depth)
{
	if($start_level_name != '0')
	{
		foreach($GLOBALS['content']["struct"] as $key => $value)
		{
			if($GLOBALS['content']["struct"][$key]['acat_alias'] == $start_level_name)
			{
				$start_id = $GLOBALS['content']["struct"][$key]['acat_id'];
			}
		}
		foreach($GLOBALS['content']["struct"] as $key => $value)
		{
			if($GLOBALS['content']["struct"][$key]['acat_struct'] == $start_id)
			{
				$navi_struct[$GLOBALS['content']["struct"][$key]['acat_alias']] = $GLOBALS['content']["struct"][$key];
			}
		}
	}
	else
	{
		foreach($GLOBALS['content']["struct"] as $key => $value)
		{
			if($GLOBALS['content']["struct"][$key]['acat_struct'] == $catID && $GLOBALS['level_count'] <= $auto_start_level + $auto_level_depth)
			{
				$navi_struct[$GLOBALS['content']["struct"][$key]['acat_alias']] = $GLOBALS['content']["struct"][$key];
			}
		}
		if(!$navi_struct && $GLOBALS['level_count'] > $auto_start_level)
		{
			foreach($GLOBALS['content']["struct"] as $key => $value)
			{
				if($GLOBALS['content']["struct"][$key]['acat_id'] == $GLOBALS['content']['cat_id'])
				{
					$akt_level = $GLOBALS['content']["struct"][$key]['acat_struct'];
				}
			}
			foreach($GLOBALS['content']["struct"] as $key => $value)
			{
				if($GLOBALS['content']["struct"][$key]['acat_struct'] == $akt_level)
				{
					$navi_struct[$GLOBALS['content']["struct"][$key]['acat_alias']] = $GLOBALS['content']["struct"][$key];
				}
			}
		}
	}
	return $navi_struct;
}
// -------------------------------------------------------------


// -------------------------------------------------------------
function get_any_level_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);
}
// -------------------------------------------------------------


// -------------------------------------------------------------
function css_any_level($struct, $catID, $start_level_name="", $auto_start_level="", $auto_level_depth="", $back_link="", $hide_level="", $style="", $xtra_menu_style="", $xtra_li_style="", $separator="", $link_to="index.php")
{
	$start_level_name = trim($start_level_name);
	$auto_start_level = intval($auto_start_level);
	$auto_level_depth = intval($auto_level_depth);
	$back_link = trim($back_link);
	$hide_level = trim($hide_level);
	$style = trim($style);
	$xtra_menu_style = trim($xtra_menu_style);
	$xtra_li_style = trim($xtra_li_style);
	$separator = htmlentities(trim($separator));
	$css_list = "";
	if($hide_level != '0')
	{
		$hide_level = explode(",", $hide_level);
	}
	if($style == '0')
	{
		$style = 'any_navi';
	}
	if($separator == '0')
	{
		unset($separator);
	}

	$navi_struct = get_navi_struct($catID, $start_level_name, $auto_start_level, $auto_level_depth);
	$breadcrumb = get_any_level_breadcrumb($GLOBALS['content']["cat_id"], $GLOBALS['content']['struct']);
	$act_cat = $GLOBALS['content']['struct'][$GLOBALS['content']['cat_id']]['acat_alias'];

	if($navi_struct)
	{
		foreach($navi_struct as $key => $value)
		{
			if(is_array($hide_level) && in_array($navi_struct[$key]['acat_alias'], $hide_level))
			{
				unset($navi_struct[$key]);
			}
			if($navi_struct[$key]['acat_hidden'] == '1')
			{
				unset($navi_struct[$key]);
			}
		}

		foreach($navi_struct as $key => $value)
		{
			if($start_level_name == '0' && $back_link != '0')
			{
				$back_link_id = $navi_struct[$key]['acat_struct'];
			}
			if($xtra_menu_style == '1')
			{
				$back_link_id = $navi_struct[$key]['acat_struct'];
			}
		}
	}

	if($start_level_name == '0' && $GLOBALS['level_count'] < $auto_start_level)
	{
		unset($navi_struct);
	}

	if($navi_struct)
	{
		if($start_level_name == '0' && $back_link != '0' && $GLOBALS['level_count'] > $auto_start_level)
		{
			if(!array_key_exists($act_cat, $navi_struct)
			|| (array_key_exists($act_cat, $navi_struct) && $GLOBALS['level_count'] > $auto_start_level + 1))
			{
				if($back_link == '1')
				{
					$name = $GLOBALS['content']['struct'][$back_link_id]['acat_name'];
				}
				else
				{
					$name = $back_link;
				}

				foreach($GLOBALS['content']['struct'] as $key => $value)
				{
					$back_link_alias = $GLOBALS['content']['struct'][$back_link_id]['acat_struct'];
				}

				$link = $link_to . "?" . $GLOBALS['content']['struct'][$back_link_alias]['acat_alias'];
				$css_list .= '<li id="' . $style . '_back"><a href="' . $link . '">' . $name . '</a></li>' . "\n";
				if($separator)
				{
					$css_list .= "<li>" . $separator . "</li>\n";
				}
			}
		}

		foreach($navi_struct as $key => $value)
		{
			if($navi_struct[$key]['acat_redirect'] != "")
			{
				$link = $navi_struct[$key]['acat_redirect'];
			}
			else
			{
				$link = $link_to . "?" . $navi_struct[$key]['acat_alias'];
			}

			if(in_array($navi_struct[$key]["acat_alias"], $breadcrumb))
			{
				if($xtra_menu_style == '1' && $xtra_li_style == '0')
    			{
    				$menu_style = $GLOBALS['content']['struct'][$back_link_id]['acat_alias'];
					$css_list .= '<li id="' . $style . '_' . $menu_style . '_active"><a id="' . $style . '_current" href="' . $link . '">';
				}
				else if($xtra_menu_style == '1' && $xtra_li_style == '1')
    			{
					$css_list .= '<li id="' . $style . '_' . $navi_struct[$key]['acat_alias'] . '_active"><a id="' . $style . '_current" href="' . $link . '">';
				}
				else if($xtra_menu_style == '0' && $xtra_li_style == '1')
    			{
					$css_list .= '<li id="' . $style . '_' . $navi_struct[$key]['acat_alias'] . '_active"><a id="' . $style . '_current" href="' . $link . '">';
				}
				else
				{
					$css_list .= '<li id="' . $style . '_active"><a id="' . $style . '_current" href="' . $link . '">';
				}
			}
			else
			{
				if($xtra_li_style == '0')
				{
					$css_list .= '<li><a href="' . $link . '">';
				}
				else
				{
					$css_list .= '<li id="' . $style . '_' . $navi_struct[$key]['acat_alias'] . '"><a href="' . $link . '">';
				}
			}
			$css_list .= html_specialchars($navi_struct[$key]["acat_name"]) . "</a>";
			$css_list .= "</li>\n";
			if($value != end($navi_struct) && $separator)
			{
				$css_list .= "<li>" . $separator . "</li>\n";
			}
   		}
    }

    if($css_list)
    {
    	if($xtra_menu_style == '1')
    	{
    		$menu_style = $GLOBALS['content']['struct'][$back_link_id]['acat_alias'];
    		$css_list = "<div id=\"".$style."_".$menu_style."\">\n  <ul id=\"".$style."_".$menu_style."_ul\">\n". $css_list ."  </ul>\n</div>";
    	}
    	else
    	{
    		$css_list = "<div id=\"".$style."\">\n  <ul id=\"".$style."_ul\">\n". $css_list ."  </ul>\n</div>";
    	}
    }
    return $css_list;
}
// -------------------------------------------------------------


// -------------------------------------------------------------
if(!( strpos($content["all"],'{NAV_ANY_LEVEL')===false ) )
{
   $content["all"] = str_replace('{NAV_ANY_LEVEL}', css_any_level($content["struct"],$content["cat_id"]), $content["all"]);
   $content["all"] = preg_replace('/\{NAV_ANY_LEVEL:(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?):(.*?)\}/e', 'css_any_level($content["struct"],$content["cat_id"],"$1","$2","$3","$4","$5","$6","$7","$8","$9")', $content["all"]);
}
// -------------------------------------------------------------

?>

Example Style:

Code: Select all

#any_navi
{
	
}
#any_navi ul
{
	font-size: 10px;
	margin: 0;
	padding: 0;
}
#any_navi li
{
	list-style: none;
	display: inline;
	color: #999999;
}
#any_navi a:link, #any_navi a:visited
{
	color: #999999;
	font-weight: bold;
	text-decoration: none;
}
#any_navi a:hover, #any_navi_active a:link, #any_navi_active a:visited, #any_navi_active a:hover, #any_navi_active a:active
{
	color: #000000;
	font-weight: bold;
	text-decoration: none;
}
Grüzli - Andi
Last edited by wingover on Wed 15. Mar 2006, 22:27, edited 9 times in total.
---------------------------------------------------
Vol Libre - der Traum vom freien Fliegen
http://www.gleitschirm-taxi.de
Faszination Berge
http://www.mountain-panorama.com
---------------------------------------------------
Pauli
Posts: 92
Joined: Mon 30. Aug 2004, 11:53

Post by Pauli »

Wonderful!!! This was just what I needed, thank you!

I just made this entirely with your RT:

Image
phalancs
Posts: 793
Joined: Thu 19. Feb 2004, 05:09
Location: Germany

Post by phalancs »

I just made this entirely with your RT:
Great, how did you manage to create these sculptures with this Replacement Tag?

:wink:
2008
Pauli
Posts: 92
Joined: Mon 30. Aug 2004, 11:53

Post by Pauli »

haha yeah it was tough :D

anyways, about the navigation, this is what I used:

Code: Select all

{NAV_ANY_LEVEL:portfolio:0:6:0:bronzenbeelden,fotografie,divers:any_navi:1:|}
{NAV_ANY_LEVEL:houtensculpturen:0:6:0:0:any_navi:1:|}
[BR]
{NAV_ANY_LEVEL:portfolio:0:6:0:houtensculpturen,fotografie,divers:any_navi:1:|}
{NAV_ANY_LEVEL:bronzenbeelden:0:7:0:0:any_navi:1:|}
[BR]
{NAV_ANY_LEVEL:portfolio:0:6:0:bronzenbeelden,houtensculpturen,divers:any_navi:1:|}
{NAV_ANY_LEVEL:fotografie:0:13:0:0:any_navi:1:|}
[BR]
{NAV_ANY_LEVEL:portfolio:0:6:0:bronzenbeelden,houtensculpturen,fotografie:any_navi:1:|}
{NAV_ANY_LEVEL:divers:0:14:0:0:any_navi:1:|}
I put this in a hidden article, and use it with a 'contentpart alias' on every article I want it to appear. Sometimes it can be so simple!
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

Hey wingover
I have problems selecting the active menu... using css

could you post some example code what you did to make the selection work, including a LIVE example

thanks
TriP
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

I have also changed the reptag to allow title/alt tags to get the link name
:-)
trip
Posts: 657
Joined: Tue 17. Feb 2004, 09:56
Location: Cape Town, South Africa
Contact:

Post by trip »

Hi
all sorted, got the active to work....
Kosse helped with some editing on the css, all to do with the UL being selected :-)
long frustrating story

TriP
wingover
Posts: 58
Joined: Wed 13. Apr 2005, 13:18
Contact:

Post by wingover »

Hi TriP,

do you have solved your problems?

I made a a litte add to the reptag. Now the current link has id="current".
Maybe sometimes it`s not enough that the <li> is marked as active.

Here some sites, I used the tag:
http://www.vm-mediaservice.de (all menus made with nav_any_level, the sitemap with nav_struct)

http://test.changeplusconsulting.de (everything with nav_any_level, site is under construction)

http://web79.s21-ffm-r03.gn-s.net/gcreit/ (main and bottom with nav_any_level, submenu with nav_struct, site is under construction)


A good site with many list/style examples is this:
http://css.maxdesign.com.au/


If you have some problems, send me a mail.


Andi
---------------------------------------------------
Vol Libre - der Traum vom freien Fliegen
http://www.gleitschirm-taxi.de
Faszination Berge
http://www.mountain-panorama.com
---------------------------------------------------
User avatar
pico
Posts: 2595
Joined: Wed 28. Jul 2004, 18:04
Location: Frankfurt/M Germany
Contact:

Post by pico »

Hi

have also a Problem with the '_active' in the generated Code - see Sample

Code: Select all

<div id="any_navi">
  <ul id="any_navi_ul">
<li id="any_navi_active"><a id="any_navi_current" href="index.php?index">Home</a></li>
<li><a href="index.php?ebene1">ebene1.1</a></li>
<li><a href="index.php?ebene2">ebene2.1</a></li>
<li id="any_navi_active"><a id="any_navi_current" href="index.php?a">a</a></li>

  </ul>
</div>
"Home" is as '_active' marked, but it isn't only "a" should be.
I use the Tag like {NAV_ANY_LEVEL:index:0:0:0:0:any_navi:0:0:0}

any hints?
Lieber Gott gib mir Geduld - ABER BEEIL DICH
Horst - find me at Musiker-Board
Patric
Posts: 2
Joined: Tue 18. Apr 2006, 11:51

Post by Patric »

Hi Wingover,

saubere Arbeit. Aber vielleicht kannst du mir direkt eine Frage beantworten bevor ich hier in Chaos versinke :-)

Ich benötige für eine Seite ein Reiter-menü das ganze soll so aussehen:

http://css.maxdesign.com.au/listamatic2 ... ntal05.htm#



Die Page-Struktur sieht so aus:

Code: Select all

Page
   |
   +--DE
         +---Ebene 1
         |        +----Ebene 2
         |        |          +----Ebene 3
         |        |          +----Ebene 3
         |        |
         |        +----Ebene 2        
         |                   +----Ebene 3
         |                   +----Ebene 3
         +---Ebene 1
                  +----Ebene 2
                  |          +----Ebene 3
                  |          +----Ebene 3
                  |
                  +----Ebene 2        
                             +----Ebene 3
                            +----Ebene 3
Ebene 1 und 2 sollen das horizontale Menü ergeben. Das heißt Ebene 1 soll in der oberen Leiste erscheinen und Ebene 2 in der darunter. Ebene 3 interessiert hierbei nicht, das mache ich in einem vertikalem Menü an der Seite....

Meinst du das wäre mit Hilfe deines Scripts mögich? Sonst muss ich es mir halt anpassen :-)

Wäre super wenn du vielleicht ne Idee hast!
Gruß Patric
User avatar
flip-flop
Moderator
Posts: 8178
Joined: Sat 21. May 2005, 21:25
Location: HAMM (Germany)
Contact:

Post by flip-flop »

Hi Patric,

eine Alternative wäre http://www.phpwcms.de/forum/viewtopic.php?t=8479

Gruß Knut
>> HowTo | DOCU | FAQ | TEMPLATES/DOCS << ( SITE )
Patric
Posts: 2
Joined: Tue 18. Apr 2006, 11:51

Post by Patric »

PERFEKT!!! Danke das ist genau was ich gesucht habe!!!!! :-) *freu*

Danke!!!!


Muss ich nachher direkt mal testen :-)
ssyfrig
Posts: 364
Joined: Tue 2. Mar 2004, 17:01
Location: Zürich / Switzerland
Contact:

Post by ssyfrig »

Hi

hmm, I don't understand this RT... :oops: :oops: Can some body explain me more in detail?

Maybe by icq or skype...

Thanks, Sven
grantdutoit
Posts: 10
Joined: Wed 12. Apr 2006, 19:25
Contact:

{NAV_ANY_LEVEL Tag Generator} installation

Post by grantdutoit »

hi,

im not a programmer so please forgive me. how do i install the reptag {NAV_ANY_LEVEL Tag Generator}

Grant :?:
wingover
Posts: 58
Joined: Wed 13. Apr 2005, 13:18
Contact:

Post by wingover »

Hi!

Pico, do you have solved you problem? The code should be correct. The 'li' is marked as the active 'li' and the 'a' as the active 'a'. So you can define all with css...

#######################################

A site, I used this tag is: http://www.publicdesign.de
This site has 3 navigations (top, left, bottom). I have one html-template using the tag 3 times. Look at the subnavi on the left side. It changes the color for every parent menu, but it`s only one template and one tag for the subnavi...

#######################################

To install the reptag, mak a file like 'reptag_nav_any_level.php' or so in 'phpwcms_template\inc_script\frontend_render' und copy the script.
Then put it on the right place in your html-template and set the options to your needs.


Grüzli - Andi
---------------------------------------------------
Vol Libre - der Traum vom freien Fliegen
http://www.gleitschirm-taxi.de
Faszination Berge
http://www.mountain-panorama.com
---------------------------------------------------
Post Reply