[Solved] Help with Menu Manager Script

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Post Reply
afri-can
Forum Members
Forum Members
Posts: 21
Joined: Tue Jun 24, 2008 5:03 pm

[Solved] Help with Menu Manager Script

Post by afri-can »

Hi all

I used the below menu manager script to turn section headers into usable menus
All works fine except the section headers menus ( the first two, about us and content owners) when active, link to # instead of the current page, can any one help me fix this

URL of test site: Removed link

Code: Select all

{* CSS classes used in this template:
#active - The active/current page
.sectionheader - To style section header
hr.separator - To style the ruler for the separator *}
{if $count > 0}

<ul>
{foreach from=$nodelist item=node}
{if $doheaderlink == "1"}
{assign var="doheaderlink" value="0"}
<li class="sectionheader"><a href="{$node->url}">{$headertext}</a>
{/if}
{if $node->depth == 1 or $showchildren == 1}
{if $node->depth > $node->prevdepth}
{repeat string="<ul>" times=$node->depth-$node->prevdepth}
{assign var="listopen" value="1"}
{elseif $node->depth < $node->prevdepth}
{if $listopen == "1"}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
{assign var="listopen" value="0"}
{/if}
</li>
{elseif $node->index > 0}</li>
{/if}

{if $node->current == true}
<li><a href="{$node->url}" class="currentpage"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{elseif $node->parent == true && $node->depth == 1}
<li> <a href="{$node->url}" class="activeparent"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{elseif $node->type == 'sectionheader'}
{assign var="doheaderlink" value="1"}
{if $node->parent == true}
{* NOTE: Disabled showing of children here *}
{assign var="showchildren" value="0"}
{else}
{assign var="showchildren" value="0"}
{/if}
{assign var="headertext" value=$node->menutext}
{elseif $node->type == 'separator'}
<li id="separator">
{else}
<li><a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>{/if}
{/if}

{/foreach}
{if $listopen == "1"}
{repeat string="</li></ul>" times=$node->depth-1}
{/if}
</li>
<li id="empty"></li>
</ul>

{/if}
Last edited by afri-can on Wed Jul 16, 2008 6:20 am, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Help with Menu Manager Script

Post by Dr.CSS »

A sectionheader is just that the head of a section like my site, the only link in my main menu that is an actual page is Home all the rest are sectionheaders...

What you need is a default menu template with the parameter number_of_levels="1" so it only shows the top level of menu items...
afri-can
Forum Members
Forum Members
Posts: 21
Joined: Tue Jun 24, 2008 5:03 pm

Re: Help with Menu Manager Script

Post by afri-can »

If you have a look at the site I am building you can see the way I was requested by the client to show the pages
My top header is all seperator headers the link links to the first child wich is the same name as the top menus, the code makes the seperator headers links  to the first child that has the same name as the top menu,
If you look at the link removed link you can see the top menu link "about us" is a seoerator header and about us in the sub menu is the first child under the about us (seperator header). From all the other pages on the site when clicking on the top menu about us you get to the correct page but when the top menu button is about us then it link to #

The bit of code from the previous code is this post is thsi

Code: Select all

{elseif $node->parent == true && $node->depth == 1}
<li> <a href="{$node->url}" class="activeparent"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>
Last edited by afri-can on Wed Jul 16, 2008 6:19 am, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Help with Menu Manager Script

Post by Dr.CSS »

OK so instead of section headers make it Content Type: internal link and put it to the page then it will always point to that page w/o the /# ....
afri-can
Forum Members
Forum Members
Posts: 21
Joined: Tue Jun 24, 2008 5:03 pm

Re: Help with Menu Manager Script

Post by afri-can »

I tried that but if I make a page an internal link page all its children are not linkable, they do not appear in the internal link dropdown
the way I did it works fine it is just a small change to the code that I do not have enough knowledge to change, i need to have the chidren under the correct section for submneu purposes
Last edited by afri-can on Sun Jul 13, 2008 8:27 pm, edited 1 time in total.
User avatar
Dr.CSS
Moderator
Moderator
Posts: 12711
Joined: Thu Mar 09, 2006 5:32 am

Re: Help with Menu Manager Script

Post by Dr.CSS »

Have you tried putting {$node->url} in the menu template where it puts the #, which is from not getting a url...
afri-can
Forum Members
Forum Members
Posts: 21
Joined: Tue Jun 24, 2008 5:03 pm

Re: Help with Menu Manager Script

Post by afri-can »

Corrected by using PHP

Added this:

Code: Select all

{php}
function selfURL() { 
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; 
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); 
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } 
function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }
{/php}
Changed This:

Code: Select all

{elseif $node->parent == true  && $node->depth == 1}
<li class="activeparent"><a href="{$node->url}" class="activeparent"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext}</a>


To This:

Code: Select all

{elseif $node->parent == true  && $node->depth == 1}
<li class="activeparent"><a href="{php} print(selfURL()); {/php}" class="activeparent"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext}</a>

any way of making it more elegant

see full code:


Code: Select all

{* CSS classes used in this template:
#active - The active/current page
.sectionheader - To style section header
hr.separator - To style the ruler for the separator *}

{php}
function selfURL() { 
$s = empty($_SERVER["HTTPS"]) ? '' : ($_SERVER["HTTPS"] == "on") ? "s" : "";
$protocol = strleft(strtolower($_SERVER["SERVER_PROTOCOL"]), "/").$s; 
$port = ($_SERVER["SERVER_PORT"] == "80") ? "" : (":".$_SERVER["SERVER_PORT"]); 
return $protocol."://".$_SERVER['SERVER_NAME'].$port.$_SERVER['REQUEST_URI']; } 
function strleft($s1, $s2) { return substr($s1, 0, strpos($s1, $s2)); }
{/php}

{if $count > 0}

<ul>
{foreach from=$nodelist item=node}
{if $doheaderlink == "1"}
{assign var="doheaderlink" value="0"}
<li class="sectionheader"><a href="{$node->url}">{$headertext}</a>
{/if}
{if $node->depth == 1 or $showchildren == 1}
{if $node->depth > $node->prevdepth}
{repeat string="<ul>" times=$node->depth-$node->prevdepth}
{assign var="listopen" value="1"}
{elseif $node->depth < $node->prevdepth}
{if $listopen == "1"}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
{assign var="listopen" value="0"}
{/if}
</li>
{elseif $node->index > 0}</li>
{/if}

{if $node->current == true}
<li><a href="{$node->url}" class="currentpage"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{elseif $node->parent == true  && $node->depth == 1}
<li class="activeparent"><a href="{php} print(selfURL()); {/php}" class="activeparent"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext}</a>

{elseif $node->type == 'sectionheader'}
{assign var="doheaderlink" value="1"}
{if $node->parent == true}
{* NOTE: Disabled showing of children here *}
{assign var="showchildren" value="0"}
{else}
{assign var="showchildren" value="0"}
{/if}
{assign var="headertext" value=$node->menutext}
{elseif $node->type == 'separator'}
<li id="separator">
{else}
<li><a href="{$node->url}"{if $node->target ne ""} target="{$node->target}"{/if}>{$node->menutext}</a>{/if}
{/if}

{/foreach}
{if $listopen == "1"}
{repeat string="</li></ul>" times=$node->depth-1}
{/if}
</li>
</ul>

{/if}
Post Reply

Return to “CMSMS Core”