new replacement tag {NAV_LIST_FROM}

Post custom hacks and enhancements for phpwcms here only. Maybe some of these things will be included in official release later.
dibeja
Posts: 8
Joined: Tue 2. Nov 2004, 15:41

new replacement tag {NAV_LIST_FROM}

Post by dibeja »

Hi, i needed a css list menu (like NAV_LIST_TOP) acting like BREADCRUMBS:site_level so I cheated up a bit the NAV_LIST_TOP code.

Here's the code

Code: Select all

function css_list_from($struct, $struct_path, $level, $grounding=0, $homelink="Home", $class="list_top", $starting="0", $link_to="index.php" ) { 
   // returns list <div><ul><li></li></ul></div> of level 0 
   // if $homelink is not empty it will also create a "Home" link 
   // you can set $homelink to the name you like 
   // predefined class for this menu is "list_top"    
    
   if(!trim($class)) $class = "list_top"; 
   $homelink = trim($homelink); 
   $level = intval($level); 
   $activated = 0; //no active list set 
   $css_list = ""; 
    $catids = ","; 
    
   //returns the complete top level AND home of NON hidden categories 
   //$top_struct = return_struct_level($struct, 0); 
   if ($starting){
       $starting = intval($starting);
   } else {
	$starting = 0;
   }
   
   $top_struct = return_struct_level($struct, $starting); 


   //return complete cat path as string 
   while ($level) { 
      $catids .= "$level,"; 
      $level = $struct[$level]["acat_struct"]; 
   } 

   if(sizeof($top_struct)) { 
      foreach($top_struct as $key => $value) { 
       
         $thisactive = 0; 
         $link  = $link_to."?"; 
         $link .= ($top_struct[$key]["acat_alias"]) ? html_specialchars($top_struct[$key]["acat_alias"]) : "id=".$key.",0,0,1,0,0"; 
         $css_list .= "    <li"; 
          
         if ($grounding) { 
           if (strstr($catids, ",".$top_struct[$key]["acat_id"].",")) $thisactive = 1; 
         } else if($struct_path[$key]) $thisactive=1; 

         if($thisactive) { 
           $css_list .= " id=\"".$class."_active\""; 
             $activated = 1; 
         } 
                   
         $css_list .= '><a href="'.$link.'"'; 
         $css_list .= (!$thisactive) ? "" : " class=\"".$class."_active_link\""; 
         $css_list .= ' target="_top">'.html_specialchars($top_struct[$key]["acat_name"])."</a>"; 
         $css_list .= "</li>\n"; 
      } 
   } 
    
   if($homelink) { 
      $css_list_home  = "    <li id=\"".$class. ((!$activated) ? "_home_active" : "_home") ."\">"; 
      if($starting > 0){
		$css_list_home .= '<a href="'.$link_to.'?id=' . $starting . ',0,0,1,0,0"';
	} else {
		$css_list_home .= '<a href="'.$link_to.'?id=0,0,0,1,0,0"'; 
	}
      $css_list_home .= ($activated) ? "" : " class=\"".$class."_home_active_link\""; 
      $css_list_home .= ' target="_top">'.html_specialchars($homelink)."</a>"; 
      $css_list_home .= "</li>\n"; 
      $css_list = $css_list_home . $css_list; 
   } 
   if($css_list) { 
      $css_list = "<div id=\"".$class."\">\n  <ul id=\"".$class."_ul\">\n". $css_list ."  </ul>\n</div>"; 
   } 
   return $css_list; 
}


// List based navigation with Starting Level 

if( ! ( strpos($content["all"],'{NAV_LIST_FROM')===false ) ) { 
   $content["all"] = str_replace('{NAV_LIST_FROM}', css_list_top($content["struct"],$content["cat_path"],$content["cat_id"]), $content["all"]); 
   // creates a list styled top nav menu | {NAV_LIST_TOP:level:grounding:home_name:class_name} | defaults 0:home:list_top 
   //$content["all"] = preg_replace('/\{NAV_LIST_TOP:(.*?):(.*?):(.*?)\}/e', 'css_list_top($content["struct"],$content["cat_path"],$content["cat_id"], "$1", "$2", "$3")', $content["all"]); 
   $content["all"] = preg_replace('/\{NAV_LIST_FROM:(.*?):(.*?):(.*?):(.*?)\}/e', 'css_list_from($content["struct"],$content["cat_path"],$content["cat_id"], "$2", "$3", "$4", "$1")', $content["all"]); 

}
You can put this slice of code in your phpwcms_template/inc_script/frontend_render/sample.php
(So you don't mess up the core code ;))

The replacement tag sound like this:
{NAV_LIST_FROM:site_structure_id:grounding:home_name:class_name}

Thanks "captaincrash" for his grounding solution.
More information about "grounding" can be found here:
http://www.phpwcms.de/forum/viewtopic.p ... =grounding

Hope you enjoy this!
marco

Post by marco »

This is exactly one of the problems I have right now.

I guess "grounding" is synonym with highlighting the currently selected position in a menu by using a different style.
Is this correct?

The second, and bigger problem I have is that when the first (home) item in the top (horizontal) menu is selected, the side vertical menu re-displays the remaining menu options from the top menu.

What I need is each menu option in the top menu to display a specific and different vertical side menu.

e.g. Home is currently selected, and highlighted in red:

Home | News | Blog | Shop


Home (not displayed, shown just for the example)
-- HomeOption1
-- HomeOption2
-- HomeOption3

News (not displayed)
--NewsOption1
--NewsOption2
--NewsOption3

etc.


Instead of the above, when I select "Home" I get:

Home
--News
--Blog
--Shop

This would work if the NAV_LIST_TOP and NAV_ROW had an option to allow it not start with the site root level but the level below.

The site structure for the above is:

Index
--Home
---- HomeOption1
---- HomeOption2
---- HomeOption3
--News
----NewsOption1
----NewsOption2
----NewsOption3

Note that even if I set the "Home" level in my site structure to "hidden" "not visible" and "not public", it still shows up!

Any ideas how to do this?

Is it a matter of setting the site structure up differently or am I not using the tags correctly?

Could your tag be modified to allow what I described above?

By the way, I tried to redirect the "home" menu item and also to set it hidden - it does not work.
dibeja
Posts: 8
Joined: Tue 2. Nov 2004, 15:41

Post by dibeja »

"grounding" must be a value of 0 or 1 (0=disabled, 1=enabled) and it's ment to higlight the site section in wich an article resides.

For example:
if you have a link to an article in your homepage, but the article resides in your News site structure, with "grounding=1", when you follow that link, your NEWS top_link (the one in the navigation) will be the ACTIVE link.
With "grounding=0" your HOME top link will be the ACTIVE one.

For the "bigger problem" try with the {NAV_LIST_CURRENT} replacement tag.
More information here:
http://docu.fhss.de/navigation_tags.phtml

Or maybe I misunderstand the problem... let me know.

(if you're from Italy we can speak Italian, if you prefer. My email is
l.dibella@gmail.com)
marco

Post by marco »

Thank you, dibjeja, for the response.

I am from Montreal, I can understand italian but do not speak it very well. I was aware of and already read the documentation on the tags.

The problem with the NAV_LIST_CURRENT and NAV_ROW is this:

- First, the first item in NAV_ROW, which is the index or home node in the site structure, can not be hidden in the site structure, so it shows up in the menu

- Next, when this first NAV_ROW menu item (home/index) is selected , NAV_LIS_CURRENT displays all the levels immediately below the home; which is just repeating what is already shown in the NAV_ROW menu;

- What I need is for the home item in the NAV_ROW to get NAV_LIST_CURRENT to display a submenu specific to home, which is not made up of the other menu items from NAV_ROW

Is it clear what I am trying to do?

Home | News | Blog | Shop

When home is selected, I need to get;

- Home menu option 1 (not News)
- Home menu option 2 (not Blog)
- Home menu option 3 (not Shop)

and NOT:

- News
- Blog
- Shop

Why? Because the site has 4 different sections, each with content specific to it and menus specific to that section.

The problem would be easily solved if the Index (root) level simpy did not show up in any menu. Then my top level menu would be made up of first level entries from the site structure
and the vertical submenus would be sublevels of level 1 menu items. This is how it works for all menu items except for the first (index level) one.

To further compound my problem, even if I select hidden, not visible, not public, or redirect the index level, it still shows up in my navigation menus and the redirect does not work. And I don't know if this is by design, if it is a bug, or if it is something I am not doing right.
marco

Post by marco »

Well, this was one frustrating day.

It turns out that {NAV_ROW} has two parameters that allow it to do exactly what I need, {NAV_ROW:x:y}. After trial and error, I got the right combination (could not quite understand the Babelfish translation).

Unfortunately the english version of the documentation at http://docu.fhss.de/index.php?english_version did not specify this.

I finally stumbled on this by looking at the german documentation and using Babelfish to translate it.

If this is possible in wcms, it might be useful to allow comments to the documentation posts, so that people can note omissions, add suggestions or examples. The post comments could be hidden after the the post is updated.
dibeja
Posts: 8
Joined: Tue 2. Nov 2004, 15:41

Post by dibeja »

Happy you found a solution! :lol:

I think I've coded a site with the requirement you've posted.
This is the url:
http://www.agribosco.com/index.php (it's a pre-release version).
Only the italian version is working

Every section has its sub-section menu on the right side of the page (except home) {NAV_LIST_CURRENT}-driven.

If this ting can help you I can post the template code.
marco

Post by marco »

dibeja wrote:Happy you found a solution! :lol:

I think I've coded a site with the requirement you've posted.
This is the url:
http://www.agribosco.com/index.php (it's a pre-release version).
Only the italian version is working

Every section has its sub-section menu on the right side of the page (except home) {NAV_LIST_CURRENT}-driven.

If this ting can help you I can post the template code.
That is a very nice design.

You are very kind, dibeja.
I think the site menu-level structure, along with tags you used for navigation would be enough.
I'll check the source and css with "view source".

I noticed that your side menu items are hidden after a menu item is selected; is that how you wanted it?
jarocho
Posts: 6
Joined: Mon 17. May 2004, 20:06

Hola Dibeja

Post by jarocho »

Please can post the template code.

Saludos
dibeja
Posts: 8
Joined: Tue 2. Nov 2004, 15:41

Here it'is the template

Post by dibeja »

(for Marco): yes. I wanted the menu to show only section directly below the current section, cause same section has subsection in it.

For this site I have two templates (all css driven):
page layout 2 column, the small one on the right.

1 - home page:

Code: Select all

<!-- HEADER: -->
<div id="logo"><h1>Agribosco</h1></div>
{NAV_LIST_FROM:1:1:Home:nav}
<div id="breadcrumb">Home</div>

<!-- MAIN: -->
{CONTENT}

<!-- FOOTER: -->
<div id="underNav">
<p>{NAV_ROW:1:1}</p>
</div>
<div id="copy">Copyright Agribosco srl</div>

<!-- RIGHT: -->
<div id="ikuviumPane">
{PHP:http://www.agribosco.com/content/php/ikuvium.php}
</div>
<div class="sideContent">
<h3>News</h3>

</div>

<div class="sideContent">
<h3>in Evidenza</h3>
<ul>
<li>[ID 16]Il Farro[/ID]</li>
<li>[ID ricerca_it]Progetto "Sementi Antiche"[/ID]</li>
<li>[ID 25]Disciplinari di produzione[/ID]</li>
</ul>
</div>

<div class="sideContent">
<ul>
<li>[ID cerca_it]Cerca nel sito[/ID]</li>
</ul>
</div>
2 - all other pages

Code: Select all

<!-- HEADER: -->
<div id="logo"><h1>Agribosco</h1></div>
{NAV_LIST_FROM:1:1:Home:nav}
<div id="breadcrumb">{BREADCRUMB:1}</div>

<!-- MAIN: -->
{CONTENT}

<!-- FOOTER: -->
<div id="underNav">
<p>{NAV_ROW:1:1}</p>
</div>
<div id="copy">Copyright Agribosco srl</div>

<!-- RIGHT: -->
<div id="ikuviumPane">
{PHP:http://www.agribosco.com/content/php/ikuvium.php}
</div>
<div id="subnav">
<h3>Argomenti</h3>
{NAV_LIST_CURRENT:1:<< indietro:}
</div>
<div class="sideContent">
<ul>
<li>[ID cerca_it]Cerca nel sito[/ID]</li>
</ul>
</div>
marco

Post by marco »

Thank you dibeja for posting your code; it is remarkably clean and it shows well how powerful wcms and CSS are. By the way, the selection of pictures for the site is also very good, it conveys the message very well.

Did you post the entire html code in the "main" content box in the template panel? And did you use the "css div" or the "custom" option in the page layout panel?
dibeja
Posts: 8
Joined: Tue 2. Nov 2004, 15:41

Post by dibeja »

I've used the page layout with HEADER FOOTER MAIN and RIGHT COL, "css div".

I've also used an hack which enclose the "system's div" (HeaderBlock, mainBlock etc.) into a "container" div.
marco

Post by marco »

dibeja wrote:I've used the page layout with HEADER FOOTER MAIN and RIGHT COL, "css div".

I've also used an hack which enclose the "system's div" (HeaderBlock, mainBlock etc.) into a "container" div.
Ok, I see, you copied sections of your posted code in the corresponding textboxes in the "templates" panel;

but what is the hack called, where did you find it and why did you have to use it?

I placed all my html code (except the html head) in the "main" box and the layout seems to be rendered fine for either the "css div" or the "custom" option.
dibeja
Posts: 8
Joined: Tue 2. Nov 2004, 15:41

Post by dibeja »

Eher's the link to the hack I've used:
http://www.phpwcms.de/forum/viewtopic.p ... tainer+div

By using this "container" div I can set some CSS properties, like "width" or "margin: auto", one time, instead of applying this properties through all the "system divs" (HeaderBlock,mainBlock etc.).

For example:

Code: Select all

<!-- CSS -->
#container {
width: 700px;
margin-left: auto;
margin-right: auto;
}
In this way all the template divs will be enclosed in a "box" of 700px and it will be orizontally centered on screen (not in Internet Explorer...).

I found this way of html & css coding much more flexible, for my personal experience. ;)
marco

Post by marco »

Hmm, interesting...

I also use a container div; actually I use two of them to get around the ugly IE box model problems; the example is at the link below. The idea comes from the Matrjoshka hack, although is not really a hack http://www.pixy.cz/blogg/clanky/width-p ... joska.html


<div id="container"><div id="border">
...
</div></div>


I found that I can paste the container div's without problem, along with the rest of the code, in the "main" box in the template panel.

But I have not yet tried to paste the idividual html code sections in the different template boxes (as you did); maybe that's why the hack is needed, I don't know... I guess I'll find out when I try it.
marco

Post by marco »

I am trying to use
{NAV_LIST_FROM:0:0::topnav}
to get a top level list-based menu styled like this:

Home | Contact | Site Map

The first and last list elements are styled differently, and the default Home link is the current one by default.

Here's the list:

<div id="topnav">
<ul>
<li class="first"><a href="index.php?home"
class="current">Home</a></li>
<li><a href="index.php?contact_pks">Contact</a></li>
<li class="last"><a href="#">Site Map</a></li>
</ul>
</div>

The problem I have is that I can not get the first and last items styled differently if I use the tag

Is there a way to do what I want with this tag?

My default solution is to not use replacement tags but the above ul/li list
Post Reply