New variable to Menu Manager node

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
Rallu

New variable to Menu Manager node

Post by Rallu »

Hello guys, I want to tell you that your piece of software over here is really nice. It's even better than my commercial CMS ;). I was playing with Menu Manager today and I wanted to list simply links to pages that have same parent as current page (=sisters). I think it was way too big hassle with Smarty templates since I had to check depth and record parent so I slightly modified MenuManager::FillNode().

old code:

Code: Select all

// snip... //
		$onenode->parent = false;
		$count++;

		if (isset($gCms->variables['content_id']) && $onenode->id == $gCms->variables['content_id'])
			$onenode->current = true;
		else
		{
			$onenode->current = false;
			//So, it's not current.  Lets check to see if it's a direct parent
			if (strstr($gCms->variables["friendly_position"] . '.', $content->Hierarchy() . '.') == $gCms->variables["friendly_position"] . '.')
			{
				$onenode->parent = true;
			}
		}
// snip... //
new code:

Code: Select all

// snip... //
		$onenode->parent = false;
		$onenode->sister = false;
		$count++;

		if (isset($gCms->variables['content_id']) && $onenode->id == $gCms->variables['content_id'])
			$onenode->current = true;
		else
		{
			$onenode->current = false;
			//So, it's not current.  Lets check to see if it's a direct parent
			if (strstr($gCms->variables["friendly_position"] . '.', $content->Hierarchy() . '.') == $gCms->variables["friendly_position"] . '.')
			{
				$onenode->parent = true;
			}
			//If it is not current or parent then it might be sister...
			else if (substr($gCms->variables["friendly_position"], 0, -2) == substr($content->Hierarchy(), 0, -2)) 
			{
				$onenode->sister = true;
			} 
		}
// snip... //
Then asking only sisters should be more simple.

Keep up the good work with the CMS,
Rallu
Rallu

Re: New variable to Menu Manager node

Post by Rallu »

Gee... I'm eager to post my code too fast without thinking. Of course it doesn't work when last number of hierarchy goes over 9...
Rallu

Re: New variable to Menu Manager node

Post by Rallu »

New try:

Code: Select all

// snip... //
		$onenode->parent = false;
		$onenode->sister = false;
		$count++;

		$sister_tmp1 = explode(".", $gCms->variables["friendly_position"]);
		$sister_tmp2 = explode(".", $content->Hierarchy()); 
		array_pop($sister_tmp1);
		array_pop($sister_tmp2);

		if (isset($gCms->variables['content_id']) && $onenode->id == $gCms->variables['content_id'])
			$onenode->current = true;
		else
		{
			$onenode->current = false;
			//So, it's not current.  Lets check to see if it's a direct parent
			if (strstr($gCms->variables["friendly_position"] . '.', $content->Hierarchy() . '.') == $gCms->variables["friendly_position"] . '.')
			{
				$onenode->parent = true;
			}
			else if ($sister_tmp1 == $sister_tmp2) 
			{
				$onenode->sister = true;
			} 
		}
// snip... //
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am
Location: Arizona

Re: New variable to Menu Manager node

Post by Dr.CSS »

Nice, but it seems like you could have done this with 2 menus one shows 1st level menu items second shows 2nd level items of main menu current item.

Example of it used this way...

http://www.multiintech.com/index.php?page=panoramica
Rallu

Re: New variable to Menu Manager node

Post by Rallu »

What I wanted was one menu that prints current page parent, sisters, itself and siblings.

Here is template code if you want to test. It assumes that it won't be used to root node other wise it won't be printing the first .
It works quite well on the site where depth goes 10 and every page in every level has about 10 subpages.

list_parent_sisters_siblings:

Code: Select all

{if $count > 0}
{foreach from=$nodelist item=node}
{if $node->current == true}
{* depth of the current page to find out parent *}
{assign var="current_depth" value=$node->depth}
{/if}
{/foreach}
{foreach from=$nodelist item=node}
{if $current_depth-1 == $node->depth && $node->parent} 
<h2>{$node->menutext}</h2><ul>
{/if}
{if $node->sister}
{* clear depth so that we don't list siblings of sister nodes *}
{assign var="depth" value=""}
{if $listopened == 1}
{assign var="listopened" value="0"}
</ul></li>
{/if}
<li><a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a></li>
{/if}
{if $node->current}
<li id="active">{$node->menutext}
{if $node->haschildren}
{assign var="listopened" value="1"}
<ul>    
{/if}
{/if}
{if $depthcheck == 1 && $node->depth-1 == $node->prevdepth}
{assign var="depth" value=$node->depth}
{assign var="depthcheck" value="0"}
{/if}
{if $node->depth == $depth}
<li><a href="{$node->url}"{if $node->target != ""} target="{$node->target}"{/if}>{$node->menutext}</a></li>
{/if}
{if $node->current && $node->haschildren}
{assign var="depthcheck" value="1"}
{/if}
{/foreach}
{if $listopened == 1}
</ul>
</li>
{/if}
</ul>
{* if count > 0 *}
{/if}
Post Reply

Return to “Developers Discussion”