Show_Menu2 - README + Solutions for different navigations

badknight

Because there are so many solutions for different navigations with the show_menu2, you can find some solutions in this thread

Please note: This post will be updated from time to time

Vorab, gibt es aber noch eine kurze Einleitung zu Show_Menu2.

What is Show_Menu2?
QuoteA code snippet for the Website Baker CMS software. It provides a complete
replacement for the builtin menu functions. All menu data is retrieved using
a single database query, all types of menu styles (lists, breadcrums, sitemaps)
can be generated with extensive customisation of the resulting HTML.
Quelle: /modules/show_menu2/README.en.txt

Using Show_Menu2:
Quote
You need to modify the PHP files of your template to call show_menu2 where you
wish to have the menu displayed. Remember when you replace calls to the old
menu functions to use the new parameters that show_menu2 requires.

Often times the default menu generated by show_menu2 is all that you need.
This menu shows the current page and children of the current page. It is
generated by just calling show_menu2 with no parameters. For example:
   
    show_menu2();

Note that the call to show_menu2 is PHP, so you usually need to wrap it in the
PHP code brackets so that it will execute. Like this:

    <?php show_menu2(); ?>
Quelle: /modules/show_menu2/README.en.txt

Function:
The complete call signature and default parameter value for show_menu2 is:


    show_menu2(
        $aMenu          = 0,
        $aStart         = SM2_ROOT,
        $aMaxLevel      = SM2_CURR+1,
        $aOptions       = SM2_TRIM,
        $aItemOpen      = '[li][a][menu_title]</a>',
        $aItemClose     = '</li>',
        $aMenuOpen      = '[ul]',
        $aMenuClose     = '</ul>',
        $aTopItemOpen   = false,
        $aTopMenuOpen   = false
        )

Quote$aMenu will be 0 for most people.
   
   $aStart must be either a page ID or a value starting with "SM2_".
   
    $aMaxLevel must be only values that start with "SM2_".
   
    $aOptions must be only values that start with "SM2_" (unless you are in a very small minority of users).
   
    All other parameters are the HTML tag templates that will be output for menus and menu items.
   
    Note that every parameter from $aItemOpen can be supplied as false to get the default value.
Quelle: /modules/show_menu2/README.en.txt

Parameters:
Quote
$aMenu     
    Menu number to use. This is useful when you are using multiple menus.
    Supplying a menu number of 0 will use the default menu for the current
    page. Supplying SM2_ALLMENU will return all menus in the system.

$aStart 
    Specify where the menu generation should start from. This is most
    times the parent item of the menu to display. It must be one of the
    following values:

        SM2_ROOT+N  Start N levels down from the root. e.g.
                      SM2_ROOT      Starting at the root menu
                      SM2_ROOT+1    Start 1 level below the root
                      SM2_ROOT+2    Start 2 levels below the root

        SM2_CURR+N  Start N levels down from the current page level. e.g.
                      SM2_CURR      Starts at the current page level. All
                                    sibling menus to the current page.
                      SM2_CURR+1    Starts 1 level down from the current
                                    page with the children menus.

        page_id    Display using the specific page as the parent. All
                    child menus of that page will be displayed. The
                    page_id can be found by editing the page in WB admin
                    interface. The page_id is included in the URL like: http://SITE/admin/pages/modify.php?page_id=35

$aMaxLevel   
     Maximum menu level to display. Menus are displayed from the start level down to this level.
       
        SM2_ALL      No limit, all levels are displayed

        SM2_CURR+N   Always show to the current page + N levels.
                     SM2_CURR      Current (no children)
                     SM2_CURR+3   All parents + current + 3 children

        SM2_START+N  Always show from the starting level + N levels. The levels of menu will always be displayed regardless of what level the current page is.
                     SM2_START     Single level of menus from starting level
                     SM2_START+1  Starting level and 1 level down

        SM2_MAX+N  Show at most N levels from the starting level. Levels won't be shown if they are below the current level.
                     SM2_MAX       Starting level only (same as SM2_START)
                     SM2_MAX+1    Maximum of starting level and 1 level.

$aOptions   
    Specify flags for different generation options for the menu. The flags
    may be combined together using bitwise OR (|). For example, to specify
    both TRIM and PRETTY you should use, (SM2_TRIM | SM2_PRETTY).

    GROUP 1
    -------
    Exactly one flag from this group must always be supplied. These flags
    affect how the siblings in the tree are removed from the output.

    SM2_ALL         Show all branches of the menu tree
                        A-1 -> B-1
                            -> B-2 -> C-1
                                   -> C-2 (CURRENT)
                                          -> D-1
                                          -> D-2
                                   -> C-3
                        A-2 -> B-3
                            -> B-4
    SM2_TRIM        Show all sibling menus of pages on the current path.
                    All sub-menus of elements that are not on the path
                    are removed.
                        A-1 -> B-1
                            -> B-2 -> C-1
                                   -> C-2 (CURRENT)
                                          -> D-1
                                          -> D-2
                                   -> C-3
                        A-2
    SM2_CRUMB       Show only the breadcrumb trail, i.e. the current
                    menu and all of it's ancestor menus.
                        A-1 -> B-2 -> C-2 (CURRENT)
    SM2_SIBLING     The same as SM2_TRIM however only sibling menus of
                    the current page are displayed. All other menus are
                    trimmed to show only the path.
                        A-1 -> B-2 -> C-1
                                   -> C-2 (CURRENT)
                                          -> D-1
                                          -> D-2
                                   -> C-3

    GROUP 2
    -------
    All of these flags are optional. Any number of them may be combined.

    SM2_NUMCLASS    Add the numbered menu classes to the menu. If this
                    flag is supplied, the "menu-N" and "menu-child-N"
                    classes will be added.
                   
    SM2_ALLINFO     Load all fields from the page table of the database.
                    This will result in quite a lot of memory being used
                    and is not recommended, however it will make keywords,
                    descriptions, and other fields available. This data
                    is not loaded by default.
                    NOTE: This flag must be used on the *FIRST* call to
                    show_menu2 *for this menu ID*, or in combination with
                    SM2_NOCACHE otherwise it will have no effect.
                   
    SM2_NOCACHE     Do not reuse or store the data read from the database
                    between calls to show_menu2.
                   
    SM2_PRETTY      Pretty print the menu HTML with spacing and newlines
                    for debugging purposes.
                   
    SM2_BUFFER      Do not output the menu HTML but instead buffer it
                    internally and return it as a string from show_menu2.
                   
    SM2_CURRTREE    Exclude all other top level menus from being considered.
                    Only items in the current menu tree will be output.
                    This can be combined with any of the Group 1 flags as
                    necessary.
                   
    SM2_ESCAPE      Call htmlspecialchars on the menu strings. This may be
                    required with older installations of WB. By escaping the
                    raw database strings, it permits menus to have HTML
                    formatting in them that would cause otherwise cause
                    pages to fail validation.
   
    SM2_SHOWHIDDEN  Hidden pages are usually hidden all of the time, including
                    when they are active (i.e. current page or a parent page).
                    Use private pages for time when you want pages to be
                    hidden except when active. However for compatibility with
                    release 4.8, supply this flag to enable hidden pages to
                    become visible when they are active.

    This parameter also has an extended mode where an associative array of
    options is supplied. See the EXTENDED OPTIONS section for details.
    Most users will NOT need to use this.
   
$aItemOpen
    Dies legt den Formatstring fest, mit dem jeder einzelne Menüeintrag begonnen
    wird. Für den allerersten Menüeintrag kann mittels $aTopItemOpen ein anderer
    Formatstring definiert werden.
    Wenn dieser Parameter auf false gesetzt wird, wird der Vorgabe Formatstring
    '
  • [a][menu_title]</a>' verwendet um die Kompatibilität zur Website Baker
        Standardfunktion show_menu() zu gewährleisten.
        Da die Formatierung mittels CSS-Klassen oftmals einfacher ist, wenn sie auf den
        <a> tag angewendet werden, empfiehlt es sich hier folgenden Formatstring zu
        verwenden: '<li>[ac][menu_title]</a>'.
       
        Dieser Parameter kann auch als Instanz eine Formatierungklasse für das Menü
        verwendet werden. Die nähere Beschreibung dazu findet sich im Abschnitt FORMATTER.
        Wenn hier ein Formatter angegeben wird, werden alle Argumente
        nach $aItemOpen ignoriert.


    $aItemOpen
        Format string to use for creating each individual menu item entry.
        A different format string may be used for the very first entry by
        supplying a different format string for $aTopItemOpen. When set to
        false, it uses the default of '
    • [a][menu_title]</a>' to maintain
          compatibility with show_menu(). Note however that CSS formatting is
          often easier if the classes are added to the <a> tag. Use the format
          string of '<li>[ac][menu_title]</a>' for this style of tag.

          This parameter may also be specified as an instance of a formatting
          class for the menu. See the section "Formatter" below for details of
          the API this class must expose. When a formatter is supplied, all
          arguments after $aItemOpen are ignored.

      $aItemClose
          String used to close each item. Note that this is not a format
          string and no keywords will be replaced. When set to false, it uses
          the default of '</li>'.

      $aMenuOpen
          Format string to use for opening a list of menu item entries. A
          different format string may be used for the very first menu by
          supplying a different format string for $aTopMenuOpen. When set to
          false, it uses the default of '[ul]'.

      $aMenuClose
          String used to close each menu. Note that this is not a format
          string and no keywords will be replaced. When set to false, it uses
          the default of '</ul>'.

      $aTopItemOpen
          Format string for the first item. When set to false, it uses the same
          format as $aItemOpen.

      $aTopMenuOpen
          Format string for the first menu. When set to false, it uses the same
          format as $aMenuOpen.
Quelle: /modules/show_menu2/README.en.txt

Please note that this is only an excerpt from the readme of show_menu2. It is recommended to read it.


Solutions for different navigations:

Please note: The most of the codes are from the readme and the demopage:

For example, to show only menu items from the top level of the menu you use:
[/list] show_menu2(0, SM2_ROOT, SM2_START);


Alternatively, to show up to two levels of the child menus of the current page:
show_menu2(0, SM2_CURR+1, SM2_CURR+2);


The full menu:
show_menu2(0, SM2_ROOT, SM2_ALL, SM2_ALL|SM2_NUMCLASS|SM2_PRETTY, false, false, '<ul class="mark [class]">');


Creating a full sitemap:
show_menu2(SM2_ALLMENU, SM2_ROOT, SM2_ALL, SM2_ALL|SM2_ALLINFO, '[li]<span class="content">[a][page_title]</a> (menu: [a][menu_title]</a>)<br /><i>[description]</i><br />([keywords])</span>', false, '<ul class="sitemap [class]">');


Breadcrumbs for the entire current path (Note: WebsiteBaker also has a separate function for: show_breadcrumbs())
show_menu2(0, SM2_ROOT, SM2_CURR, SM2_CRUMB, '<span class="[class]"> > [a][menu_title]</a>', '</span>', '', '', '<b>Sie befinden sich hier:</b> <span class="[class]">[a][menu_title]</a>');


Showing the current tree only:
show_menu2(0, SM2_ROOT, SM2_ALL, SM2_ALL|SM2_CURRTREE);


Generate a table based menu:
<table border="1">
show_menu2(0, SM2_ROOT, SM2_START, SM2_ALL, '<tr><td class="[class]">[a][menu_title]</a>', '</td></tr>', '', '');
</table>



Generate a span based menu:
show_menu2(0, SM2_ROOT, SM2_START, SM2_ALL, '<span>| [a][menu_title]</a>', ' |</span>', '', '');


check if a submenu contains items:
to the topic


Drop down with background images:
to the topic


Breadcrumbs without links:
to the topic


top-level page name from a sub page:
show_menu2(0, SM2_ROOT, SM2_CURR, SM2_CRUMB, '', '', '', '', '[menu_title]');



Some posts from the german forum:

Accordion Menu with Show_Menu2:
Zum Beitrag


Specific page, only one level deep:
show_menu2(1, 79, SM2_START+1, SM2_ALL|SM2_PRETTY);
Zum Beitrag


Same menu, title but different  page title
Zum Beitrag


Delimiters not show
CSS - solution:

<style type="text/css">
span.menu-current { display: none; } /* hier wird der Link bei Bedarf ausgeblendet */ }
span.menu-sibling { /* hier das rein, was bisher in .siblings drin war */ }
span.menu-sibling a { /* hier die Grundformatierung für den Link */ }
span.menu-sibling a:hover { /* hier die Hover-Formatierung für den Link */ }
span.menu-sibling span { /* hier die Formatierung für den Trenner (Pipe) */ }
span.menu-last span { display: none; } /* hier wird der Trenner bei Bedarf ausgeblendet */
</style>

show_menu2(
0,
SM2_CURR,
SM2_CURR,
SM2_PRETTY,
'<span class="[class]">[a][menu_title]<span> | </span></a>',
'</span>',
'',
''
);

Bedienungslösung:


<style type="text/css">
span.menu-sibling { /* hier das rein, was bisher in .siblings drin war */ }
span.menu-sibling a { /* hier die Grundformatierung für den Link */ }
span.menu-sibling a:hover { /* hier die Hover-Formatierung für den Link */ }
span.menu-sibling span { /* hier die Formatierung für den Trenner (Pipe) */ }
</style>

show_menu2(
0,
SM2_CURR,
SM2_CURR,
SM2_PRETTY,
'[if(class==menu-sibling){<span class="[class]">[a][menu_title] }][if(class==menu-sibling && class!=menu-last){<span> | </span>}][if(class==menu-sibling){</a>}]',
'[if(class==menu-sibling){</span>}]',
'',
''
);

Zum Beitrag



[gelöscht durch Administrator]
Ich würde gern die Welt verändern, doch Gott gibt mir den Quellcode nicht...