Author Topic: show_menu2: valid XHTML and CSS selectable menus  (Read 161447 times)

Offline brofield

  • Posts: 224
    • Jellycan Code
show_menu2: valid XHTML and CSS selectable menus
« on: February 20, 2006, 10:20:04 AM »
Hi,

See http://code.jellycan.com/show_menu2/ for details and updates

show_menu2 is a code snippet that provides a complete replacement for show_menu.

Features
Speed
It should be faster than the existing function as it hits the database exactly once per page load. The builtin function hits the database multiple times per function call. This is at the expense of more memory as all page information is stored locally. Realistically, the memory load is not large.

Flexibility
It can generate menus in many different ways. Covering all of the existing menu's abilities (as far as I know) and adding a few more of it's own.

Valid XHTML
The HTML generated by this function is valid XHTML.

Easy CSS styling
It generates a menu with lots of classes on each element to allow easy styling of the menu via CSS. This should allow the generated menus to be used in pretty much any way, e.g. popups, dropdowns, etc. See websites about CSS menus.

Lists, Tables, Spans, or more
Like the existing function, you can use whatever HTML tag you want to delimit the menu and menu items. UL, OL, DIV, SPAN, TR, etc. Use your imagination.

Menus or Breadcrumbs
All types of menus can be generated as well as breadcrumbs.

Demo
A demo website showing many of the different types of menus that can be created using this function is at http://code.jellycan.com/sm2test/

Documentation
See the website mentioned above for documentation.

Disadvantages
No major disadvantages to using this menu function that I can see, although suggestions are welcome. Minor ones that I can think of are:

Call Signature
It doesn't use the same call signature as show_menu (although it can if you want, just uncomment the include legacy.php line in the include.php file).

Multiple Class Names
IE for Mac has a number of bugs relating to multiple class names on a tag. Major browsers that people actually use will handle it fine though.
« Last Edit: October 16, 2008, 06:01:21 PM by brofield »

Stefan

  • Guest
Re: pure CSS menus
« Reply #1 on: February 20, 2006, 02:44:32 PM »
Sounds perfect! Good stuff!

Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #2 on: February 21, 2006, 02:49:43 AM »
Update to version 1.2 to fix a couple of minor bugs, upate the documentation and add a couple of extra features. Feature complete now I believe. See the original post for updated documentation and zip file.

Offline Hans

  • Posts: 824
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #3 on: February 21, 2006, 08:29:57 AM »
Looks good.. but how to implement this?
To be honest, the whole snippet concept isn't clear to me. Maybe an explanation about this menu feature can also help in implementing other snippets as wll.

Thanks, Hans
Hans - Nijmegen - The Netherlands

Stefan

  • Guest
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #4 on: February 21, 2006, 08:35:29 AM »
@brofield:
On your test installation, I don't find any difference between the first (full tree) and the trimmed menu. I expected the trimmed tree to look like the regular menu (for example in the stock round template).

Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #5 on: February 21, 2006, 08:36:24 AM »
  • Download the "show_menu2.zip" file attached to the original message
  • Log into the WB admin interface
  • Select "Add-Ons", then "Modules"
  • If you already have a version installed, select "show_menu2" from "Uninstall Module" list and click "Uninstall"
  • Under "Install Module", click browse and select the zip file you downloaded, then click "Install"
  • Start using the show_menu2() function in your template files

Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #6 on: February 21, 2006, 08:38:32 AM »
Yeah. I'm in the middle of testing a new version. The test site is off-limits for the moment as the results will not be what you expect.

Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #7 on: February 21, 2006, 09:28:31 AM »
Updated to version 1.4. Details in the main post. Updated zip file in the main post. test site available once again. I'm spent.

Offline PeterM

  • Posts: 182
    • www.mijnplekophetnet.nl
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #8 on: February 21, 2006, 09:39:39 AM »
This is really cool stuff, nice work  :mrgreen:

Offline ruebenwurzel

  • Posts: 8290
  • Keep on Rockin
    • Familie Gallas Online
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #9 on: February 21, 2006, 10:34:38 AM »
wooooooow  :-D  :-D  :-D

Offline PeterM

  • Posts: 182
    • www.mijnplekophetnet.nl
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #10 on: February 21, 2006, 10:57:39 AM »
Updated to version 1.4. Details in the main post. Updated zip file in the main post. test site available once again. I'm spent.

1.5?

Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #11 on: February 21, 2006, 10:59:13 AM »
Updated to version 1.6. Details in the main post. Updated zip file in the main post. Test site available once again. Fixes a couple of minor bugs I found in a code review.
« Last Edit: February 21, 2006, 11:28:49 AM by brofield »

Offline virgil

  • Posts: 179
  • Carpe diem!
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #12 on: February 21, 2006, 11:02:42 AM »
Hi everybody

yes, I know, sometimes I am really hard in understanding things  :roll: ... this IS one those miserable moments  :|

To deduce from reactions, show-menu2 must be really great... the problem is: I do not really get the difference and
the improvement in comparison to the original function, but I would like to understand because I always try to
inprove my installation, where useful.

Could somebody (in short sentences, witn no more than two syllable long words  :roll:) explain it to me?

Thank you.

Cheers
Virgil

P.S.: Eventually German explanation is welcome  :-D
        (but not a must)
Virgil - the pre-baked-stuff baker -   ;-))

Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #13 on: February 22, 2006, 02:04:20 AM »
In summary, if you don't know that you need it, then it doesn't matter one way or the other. On the other hand, there is no problem to use it instead of the builtin. The new one has the following advantages.

Speed
It should be faster as it hits the database only once per page load. The builtin function hits the database multiple times per function call. This is at the expense of more memory as all page information is stored locally. Realistically, the memory load isn't large.

Flexibility
It can generate menus in many different ways. Covering all of the existing menu's abilities (as far as I know) and adding a few more of it's own.

Valid XHTML
The existing menu function generates HTML that doesn't validate. Minor concern really, but many people like to have valid HTML.

Easy CSS styling
It generates a menu with lots of classes on each element to allow easy styling of the menu via CSS. This should allow the generated menus to be used in pretty much any way, e.g. popups, dropdowns, etc. See websites about CSS menus.

Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #14 on: February 22, 2006, 07:25:48 AM »
Updated to version 2.0. See the head post for details. This is the final update that I expect to do, aside from bug fixes.

Changes in this version are:
* optionally specify what HTML tags to use when generating the menu. Default is ul/li, but any other combination is possible, such as ol/li, tr/td, etc.
* optionally specify an ID for the top level menu tag
* demo site updated showing off these features

Stefan

  • Guest
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #15 on: February 22, 2006, 09:44:13 AM »
Valid XHTML
The existing menu function generates HTML that doesn't validate. Minor concern really, but many people like to have valid HTML.

The core function show_menu should generate valid html too... Or do you have problems with it?

Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #16 on: February 22, 2006, 09:49:22 AM »
A friend had led me to think that it was generating invalid HTML. Something like:

<ul>
   <li>item</li>
   <li>item
       <li>
           <ul>
               <li current>item<li></li></li>
               <li>item</li>
           </ul>
       </li>
   </li>
   <li>item</li>
</ul>


It must have been a communication breakdown. I'll fix the comment in the main entry.

Offline ruebenwurzel

  • Posts: 8290
  • Keep on Rockin
    • Familie Gallas Online
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #17 on: February 22, 2006, 11:04:47 AM »
@brofield

i like your new menu function i only had problems with hidden pages.

Had a main Page wich has visibility public and two subpages under this with visibility hidden. If i click on the public page link got the following error:

Code: [Select]
Warning: array_keys(): The first argument should be an array in .....\modules\show_menu2\include.php on line 247

And a question to the parameters. I Have two menus. One horizontal wich only plays the root level and a vertical submenu wich only should display the subnavigation.

Menustructure:
Page
  Subpage1
     Subpage 1.1
     Subpage 1.2

Function call:
<?php show_menu2(1, -1); ?>

Result:
when you on Main Page it shows in the submenu Subpage1 what is ok
when you on Subpage1 it shows in the submenu Subpage1, Subpage 1.1 and Subpage 1.2 what i dont like.

I'm looking for the parameter wich shows me on the Subpage1 in the submenu only the Subpage 1.1 and Subpage 1.2.

Could you pleas give me a hint how to get this?

Thanks

Matthias




Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #18 on: February 22, 2006, 11:41:01 AM »
Had a main Page wich has visibility public and two subpages under this with visibility hidden. If i click on the public page link got the following error:

Code: [Select]
Warning: array_keys(): The first argument should be an array in .....\modules\show_menu2\include.php on line 247

I don't see this error. The page http://riseup.co.nz/pages/parent.php has 3 children, 2 are hidden and 1 is private. It works fine for me there. I'm not sure how to help you without being able to reproduce the error.

I Have two menus. One horizontal wich only plays the root level and a vertical submenu wich only should display the subnavigation.

<snip>

when you on Main Page it shows in the submenu Subpage1 what is ok
when you on Subpage1 it shows in the submenu Subpage1, Subpage 1.1 and Subpage 1.2 what i dont like.

I'm looking for the parameter wich shows me on the Subpage1 in the submenu only the Subpage 1.1 and Subpage 1.2.

Could you pleas give me a hint how to get this?

Using page http://riseup.co.nz/pages/foo.php
See the example "Root Level Only" to display only the root level.
See the example "First Level" to display only the children.
I think this is what you are after, otherwise you might want "Current Children" or "Current Kids (1 level)".

Regards,
Brodie

Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #19 on: February 22, 2006, 12:22:26 PM »
Updated to version 2.1
* remove all warnings and notices when running PHP at error_reporting = E_ALL
* no other changes at all, no need to upgrade if the warnings don't affect you

Offline ruebenwurzel

  • Posts: 8290
  • Keep on Rockin
    • Familie Gallas Online
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #20 on: February 22, 2006, 02:12:54 PM »
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

Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #21 on: February 24, 2006, 06:04:03 AM »
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

Offline brofield

  • Posts: 224
    • Jellycan Code
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #22 on: February 25, 2006, 10:26:30 AM »
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)

Offline rabsaul

  • Posts: 271
    • http://www.pactumgroup.com
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #23 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?

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!

Offline ruebenwurzel

  • Posts: 8290
  • Keep on Rockin
    • Familie Gallas Online
Re: show_menu2: valid XHTML and CSS selectable menus
« Reply #24 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