show_menu2: valid XHTML and CSS selectable menus

brofield

What you are wanting to do is format the menu depending on if it has children or not (independent of what the current page is). The menu-child class indicates that the item is a child of the current page. You want to use the menu-expand class instead, which indicates that it has children. The trouble is, by using divs for both menus and menu items, it is hard to style it correctly. Add a custom class to either a menu or an item so that you can determine which one it is, or better go back to using UL/LI.

Something like...

div.menu-top { /* top level formatting */ }
div.menu-expand > div.item { /* indent formatting */ }

Menu's really fit the UL/LI structure best.

ul.menu-top { /* top level formatting */ }
ul.menu-top ul { /* sub level formatting */ }

Tim

#44
Hi Brofield,

I've implemented this snipped like you suggested in the other thread and it's working like a charm - however I have run into one small issue.

If you look at http://timtekindustries.com/wb you can see that the children (under Home) are formatted (using divs) so that they have a white left border, are indented and are in normal weighted text.

However if you click on one of those children the code that this snipped generates means that they are no longer classed as children for some reason and so they lose this formatting. However ideally I'd like for them to always maintain this bordered/indented formatting regardless of whether they are the current page or not - they're still children of the parent, but for some reason the code that show_menu2 outputs doesn't give them a child class.

Is there any way to get around this? I'm calling show_menu2() with no parameters, btw.

Thanks,
Tim

ruebenwurzel

Hello,

Thank you for this fantastic snippet. Version 2.6 works like a charm, i love it.

Matthias

brofield

Ok. I found the problem you were running into. It was only NOTIFY errors that were being produced, so the original version should have still worked, just noisily. I put up a new version of 2.6 which should solve the problem.

Cheers,
Brodie

ruebenwurzel

#41
Hello,

this is a new clean WB 2.6.2 installation and your script works perfectly till version 2.5.

QuoteI don't see how this is different from http://riseup.co.nz/pages/flidget.php
It has no subpages, yet there is no error from it.

The different is your complete Site structure has subpages. My problems are only with homepages wich have in the complete site structure no subpages. Hope this is more understandable.

Try a new clean WB installation and make only a few pages with no subpages and then try your show_menu2.

Looked at the page_trail database. So it seems that subpages have two entries (the root and the subpage) and root pages only have one entry. Could it be that your script needs a second entry on one page otherwise it produces an error? Thanks for your help. 

Matthias

brofield

I don't see how this is different from http://riseup.co.nz/pages/flidget.php
It has no subpages, yet there is no error from it.

I changed the way show_menu2 determines the parent items of the current page from doing it manually to using the page_trail data that WB stores. This appears to be what is causing the problem. It appears that the page_trail data stored for your pages is not correct.

How old is your WB installation? How many times has it been updated? Do you understand the WB database enough to check the page_trail data and see if it is stored correctly? If there is a chance that some WB databases don't correctly store this info then I will change back to the old way.

Brodie

ruebenwurzel

Hello,

So here a short description, hope its enough:

Have a page with only rootpages (now subpages) = Error on every page
Have a page with rootpages and subpages = Error only on pages without subpages

Matthias

brofield

Must've screwed something up. It works fine on my test installation, so if you can figure out what the menu structure is that causes the error then I would appreciate it. I won't get to it for a few days at least though as I am not where my computer is. In meantime I will downgrade the release.

Cheers,
Brodie

ruebenwurzel

Hello,

tried your latest version (2.6) on different installations and got always the following error:

Warning: array_keys() [function.array-keys]: The first argument should be an array in C:\Intranet\Apache2\htdocs\modules\show_menu2\include.php on line 123

Warning: Invalid argument supplied for foreach() in C:\Intranet\Apache2\htdocs\modules\show_menu2\include.php on line 123


Until 2.5 all works very fine. You change the $aMenu, so i tried it with '0' and '1' and also tried without any arguments, always the same result. Whats going wrong?

Thanks for this great code snippet and for your help

Matthias

brofield

Updated to version 2.6

* bug fix for 2.5, drop in replacement
* fixed bug where multiple page menus were not working correctly. Now defaults the menu to 0 which will use the default menu for that page (as far as I can see). Passing 1 for $aMenu will continue to get the main menu.
* added more items to the template so that now you can customize the generated item more
* a little faster
* doesn't output the menu-N and menu-child-N classes by default. Optionally turn it on.

brofield

It's a demo page for the menu generation function, not for the menu itself. The HTML is correct, it is just browser's (IE6 in particular, but also FF 1.0x and others) which can't handle it. Sure there are work arounds to make it look better in different browsers, but it doesn't really matter for a demo. In any case, I did install IE7 for the hell of it.

Cheers,
Brodie

BTW, calling Dean Edwards IE7 a "little js script" is understating it just a little, no? :-)

Stu-Art

Hi, the css menu do not work on your example page in IE 6 (http://riseup.co.nz/pages/index.php).  However you say on this page you lifted the code from the pure css menus example, which DOES work on my IE 6 and IE 7 browser. I think they apply a little js script for compliance.

Have a look here http://dean.edwards.name/IE7/compatibility/Pure%20CSS%20Menus.html

Can this be added to your improved menu code?

Stu...



kweitzel

sorry for that, replied to the other post ...

cheers

Klaus


rabsaul

No, it is not a static page. My home page is simply the top page in the site structure. It is dynamic like all the rest.

kweitzel

when you mean homepage, do you actually mean the intro page? Then you would find it is named "intro.php".

Otherwise the first page in your structure of created pages (normally the hompage) has pageid 0. But I think you mean the intropage. This is a static page and not in the DB.

cheers

Klaus

rabsaul

Thanks, Brodie.

Oops, I should have come back to this thread and mentioned that I had got another solution:

http://forum.websitebaker.org/index.php/topic,2652.0.html

As you'll see from the above, the only problem I'm having is the home page. I haven't figured out the PageName call for it, since it's being "redirected." I've tried, welcome, index, default, home, default_page, default_link etc. No luck yet.

tim

brofield

Quote from: rabsaul on February 28, 2006, 10:56:51 AM
Is there a way I can work with this code snippet to provide an "on state" for links I'm "hard-coding" into the template?

If I understand you correctly:

  • you have a fixed set of menu items that you want displayed in the top menu bar
  • you want to highlight the current page in that menu but can't at moment as using hardcoding
  • you don't want to display all top level menu items as it may change

As ruebenwurzel suggested, use a fixed parent for the menu.

  • Create a menu item and set it to invisible, this is the parent. See the admin URL for the page ID of this page, you will use it later.
  • Create the menu items in it for the top of the page below it. Use the MenuLink type. These children are visible.

This menu won't show normally because of the invisible parent. However, you can show it in your template where-ever you want by specifying the ID of the invisible parent:
<?php show_menu2(1, **INVISIBLE_PAGE_ID**, SM2_ALL, SM2_ALL); ?>

Style it using CSS:
.menu-current { font-weight: bold; }

The menu "Hidden Menu" at the demo site (see main post for URL) uses this technique.

Cheers,
Brodie

ruebenwurzel

Hello,

There is a ability to only show menus using the page_id, but I'm not shure if it's possible to define more then one page_id. Please ask brofield.

Matthias

rabsaul

Quote from: ruebenwurzel on February 28, 2006, 12:35:30 PM
Hello,

this snippet seems what you need. Looked at the link you posted above. You have a horizontal menu wich should only show the root level. This you got in your template with <?php show_menu2(1, SM2_ROOT, SM2_START); ?>. And the menu on your right side wich shows all pages you got with <?php show_menu2(); ?>.

The Layout you define in the screen.css. Your existing one should work without changes. (not shure, done only a short look on it)

Matthias
Thanks, Matthias... the thing is that this is hard-coded, and I want *only* those particular links you see there, not every page that gets created at the root level. Make sense? Will this still work somehow?

ruebenwurzel

Hello,

this snippet seems what you need. Looked at the link you posted above. You have a horizontal menu wich should only show the root level. This you got in your template with <?php show_menu2(1, SM2_ROOT, SM2_START); ?>. And the menu on your right side wich shows all pages you got with <?php show_menu2(); ?>.

The Layout you define in the screen.css. Your existing one should work without changes. (not shure, done only a short look on it)

Matthias

rabsaul

Is there a way I can work with this code snippet to provide an "on state" for links I'm "hard-coding" into the template?

I have the regular full WB nav as a vertical bar on the right hand side of my pages. However, there are a handful of basic pages that I want permanent links to in a top horizontal nav bar which I have hard-coded in. The problem is that I don't know how to show an "on state" for dynamically-generated pages.

The site is here: http://www.ccpclex.org

If this snippet won't work for that, any other ideas would be most welcome.

Thanks!

brofield

Update to version 2.5

* fixes bug with generation of crumbs.
    see "Breadcrumbs" at http://riseup.co.nz/pages/foo/fig/snot.php

* added ability set max levels. i.e. max of 2 levels, but never more than the current level
    see "Max 2 Levels" for demo of new SM2_MAX feature
    http://riseup.co.nz/pages/foo.php  (only 1 level displayed as foo is current level)
    http://riseup.co.nz/pages/foo/fig/snot.php  (only 2 levels displayed, as max is 2)

* changed the function parameters to make it a bit easier to understand
    (existing pages will have to change to match it. changes are in $aStart, $aMaxLevel and $aTrimTree only)

brofield

Upgraded to version 2.2
* fully compatible with version 2.1 call signature
* can specify multiple tags to be output for menu and items
* can generate breadcrumbs

ruebenwurzel

Hello,

Thanks for the fast response. Have testet "Current Children" and "Current Kids (1 level)" but got not the result i want. So my solution now is the following. Have three templates with three different parameter for the submenu:


  • First Template: for pages with no subpages there is no call for submenu and the content uses the whole width.
  • Second Template: for pages with subpages(first level) i use "<?php show_menu2(1, -1, -1); ?>" wich shows only the first level
  • Third Template: for pages with subsubpages(second level) i use "<?php show_menu2(1, -2, -1); ?>" wich shows only the second level

Look here: http://www.seefest-freudenberg.de. Menu is only css based.

Thanks for the great work

Matthias