two seperate menues

About the template and stylesheet - and changing the menu
manu
Posts: 1086
Joined: Wed Jun 04, 2008 12:05 pm
Location: St. Gallen - Schweiz
Contact:

two seperate menues

Post by manu » Wed Jan 30, 2013 4:34 pm

Hi
I have two seperate menues, a main navigation (vertical) and a meta navigation (horizontal).
While one menue is active, the other one should show the 1st level entries.
Is there a way to achieve this?
regards
manu

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: two seperate menues

Post by cmb » Wed Jan 30, 2013 5:04 pm

Hi manu,

to do so serverside, the server would have to be informed, which menu is active by modifying the links approriately in li(). E.g. something like:

Code: Select all

<a href="./?Welcome&menu=1" ...>Welcome</a> 
Then in the template this parameter has to be checked and acted accordingly:

Code: Select all

<?php echo !isset($_GET['menu']) || $_GET['menu'] == 1 ? toc() : toc(1,1);?>
<?php echo !isset($_GET['menu']) || $_GET['menu'] == 2 ? toc() : toc(1,1);?>
Christoph
Christoph M. Becker – Plugins for CMSimple_XH

manu
Posts: 1086
Joined: Wed Jun 04, 2008 12:05 pm
Location: St. Gallen - Schweiz
Contact:

Re: two seperate menues

Post by manu » Thu Jan 31, 2013 7:52 am

Thx Christoph,
for this fix I could read the appropriate menu from $su;

Code: Select all

<?php echo preg_match('/^menu1/',$su) ? toc(2,4) : toc(2,2);?>
but still, the wrong section would be displayed in the inactive menu.
I probably have to (use xtoc(),) render complete both the two menues and hide the "wrong" parts with style definition.
regards
manu

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: two seperate menues

Post by cmb » Thu Jan 31, 2013 11:01 am

Hi manu,

I'm still wondering, what exactly you're trying to accomplish. From the code you've posted, it seems that some page headings start with "menu1" :? and that one of the menus only should show second level (and down) headings.

Normally one can have the following two menus:

Code: Select all

<?php echo toc(1,1);?>
<?php echo toc(2,3);?>
which works fine.
manu wrote:I probably have to (use xtoc(),) render complete both the two menues and hide the "wrong" parts with style definition.
To have the full menu you can access $hc/$hl (cms.php line~301ff) and render it with li($hc, $startLevel).

Christoph
Christoph M. Becker – Plugins for CMSimple_XH

manu
Posts: 1086
Joined: Wed Jun 04, 2008 12:05 pm
Location: St. Gallen - Schweiz
Contact:

Re: two seperate menues

Post by manu » Thu Jan 31, 2013 2:26 pm

A common task is to have two navigations, one main navigation and a seperate meta navigation ("about us, impressum, contact, etc.).
My intention is to put the main navigation vertical and the meta navigation somewhere horizontal, like here.
My idea is to group the content as follows:
- mainnavi
--item1
--item2
--item3
-metanavi
--about us
--contact
--impressum

Gert
Posts: 3078
Joined: Fri May 30, 2008 4:53 pm
Location: Berlin
Contact:

Re: two seperate menues

Post by Gert » Thu Jan 31, 2013 2:32 pm

Hi Manu,

the simpliest way is, to hide impressum, contact & Co. and make a handmade navigation in a newsbox, that's easy to do with the internal links function of the editor dialog,

Gert
Last edited by Gert on Fri Feb 01, 2013 10:25 am, edited 1 time in total.
Gert Ebersbach | CMSimple | Templates - Plugins - Services

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: two seperate menues

Post by cmb » Thu Jan 31, 2013 2:56 pm

Hi manu, hi Gert,
manu wrote:My intention is to put the main navigation vertical and the meta navigation somewhere horizontal, like here.
Ah, now I understand!
Gert wrote:the simpliest way is, to hide impressum, contact & Co. and make a handmade navigation in a newsbox, that's easy to do with the internal links function of the editor dialog,
Yes, that's right. But it has a drawback: the currently selected page isn't "highlighted" in the menu.

Assuming that the number of these "meta" pages is fixed, and they're all put as last <h1> pages, there's another simple solution. Make two copies of li(), say liMeta() and liNormal() and change $ta at the beginning of them:

Code: Select all

function liMeta($ta, $st) {
    global $s, $l, $h, $cl, $cf, $u;
    $ta = array_slice($ta, -3); // use only the last three pages
...
}

function liNormal($ta, $st) {
    global $s, $l, $h, $cl, $cf, $u;
    $ta = array_slice($ta, 0, -3); // use all but the last three pages
...
} 
Then you can call in the template:

Code: Select all

<?php echo toc(1, 1, 'liMeta');?>
<?php echo toc(null, null, 'liNormal');?>
Christoph

PS: in this case the pages must not be hidden.

PPS: this solution requires CMSimple_XH 1.5.4 or above.

PPPS: even better don't make copies of li(), but instead just define the following:

Code: Select all

function liMeta($ta, $st) {
    $ta = array_slice($ta, -3);
    return li($ta, $st);
}

function liNormal($ta, $st) {
    $ta = array_slice($ta, 0, -3);
    return li($ta, $st);
} 
Last edited by cmb on Thu Jan 31, 2013 3:07 pm, edited 4 times in total.
Reason: added PS and PPS and PPPS
Christoph M. Becker – Plugins for CMSimple_XH

manu
Posts: 1086
Joined: Wed Jun 04, 2008 12:05 pm
Location: St. Gallen - Schweiz
Contact:

Re: two seperate menues

Post by manu » Thu Jan 31, 2013 4:17 pm

Then you can call in the template:

Code: Select all

    <?php echo toc(1, 1, 'liMeta');?>
    <?php echo toc(null, null, 'liNormal');?>
Nice move. But as you said, this works only with no subpages in the metanav.
My next approach is still to render both navis complete and fade out the "wrong" elements by either css/xtoc or jquery.

cmb
Posts: 14225
Joined: Tue Jun 21, 2011 11:04 am
Location: Bingen, RLP, DE
Contact:

Re: two seperate menues

Post by cmb » Thu Jan 31, 2013 4:55 pm

Well, actually it will work with subpages in the meta navigation (toc(null, null, 'liMeta'). Only the number of the meta pages has to be fix. And even this can be circumvented by dividing the normal pages from the meta pages by having a fixed "boundary". E.g. if the first meta page's heading is "About us", one can use:

Code: Select all

function liMeta($ta, $st) {
    global $cl, $h;
    $i = $cl - array_search('About us', $h);
    $ta = array_slice($ta, -$i);
    return li($ta, $st);
}

function liNormal($ta, $st) {
    global $cl, $h;
    $i = $cl - array_search('About us', $h);
    $ta = array_slice($ta, 0, -$i);
    return li($ta, $st);
} 
Christoph M. Becker – Plugins for CMSimple_XH

manu
Posts: 1086
Joined: Wed Jun 04, 2008 12:05 pm
Location: St. Gallen - Schweiz
Contact:

Re: two seperate menues

Post by manu » Thu Jan 31, 2013 5:33 pm

Ok Christoph, this is one approach, and its pretty brilliant.
I just did a test with jquery.
I have two fully rendered menues, wrapped in either a #main and a #meta div.
The jquery looks like:

Code: Select all

$(document).ready(function(){
$("#main ul.menulevel1 li").slice(-3).hide();
$("#meta ul).show();
$("#meta ul.menulevel1 li").slice(0,-3).hide();
});
which fades out the unwanted part.
For a possible noscript fallback I fade out the meta navi completely by css, which will be included in the main navi in this particular case. A possible drawback is the double toc() call. Therefore I assign the toc() to a variable:

Code: Select all

<div id="main">
<?php echo $navi_cnt = toc();?>
</div>
<div id="meta">
metanav:
<?php echo $navi_cnt;?>
</div>
This should do it. But the Christoph's one above is best.

Post Reply