Top Nav Menu with ListPages

By Helmut_pdorfHelmut_pdorf

Description

You are able to automatically build a Menu strucure on your Top navigation bar with the ListPages module - by selecting only a specific category (or tag, or combinations):

  • use the separate= "no" attribute (inserts no div's per entry)
  • use the prependLine attribute with the content of the menu-header - either
    • a literal like prependLine="* [# Menu-pages]" or
    • a link to a page like prependLine="* [[[start-buchecke | Buchecke]]]"
  • use as <custom body> of the ListPages module
    • a comment line as 1. line AND
    • as 2. line the " * %%linked_title%%" variable ( notice the space before the star!)
  • if you want you can use the limit="nn" attribute for security only not to explode the top nav menu…

Code

[[module ListPages category="buchecke" separate="no" prependLine="* [# Buchecke]"]]
[!-- --]
 * %%linked_title%%
[[/module]]
[!-- notice the comment (2.) line and the space before the star (in the 3. line  --]

Notes

1. The secret is the comment line before the variable line.. I forgot who have detected this…
Why ? The parser eliminates every space before and after a parameter value. Means: instead of " * xyz" the result is "* xyz" and the important space before the "*" is gone.
With a comment (line) before the variable the parameter has the content of "[[!-- any comment --] * Xxx" and the important space before the "*" is not erased. (Thanks to ErichSteinboeck who explained the reason in detail).

2. Another important issue is the possible, but unneccessary and dangerous space line between the different menu-items:

Avoid any blank line between the menu items. Wrong is following code:

* [[[start | Menue]]]
 * [[[start | Willkommen]]]
 * [[[Nachrichten]]]

* [[[forum:start | Forum]]]
 * [[[forum:recent-posts | Neueste Post]]]
 * [[[forum:minirecent-threads | Neueste Threads]]]

* [# Hilfe]
 * [*http://www.wikidot.com/doc Documentation]
 * [*http://www.wikidot.com/doc:wiki-syntax wiki-syntax]

* [[[contact]]]

The blank lines will create stairsteps-like menu-bars on some themes..
( thanks to mattdm for this findings)

Better is always to avoid the blank lines:

* [[[start | Menue]]]
 * [[[start | Willkommen]]]
 * [[[Nachrichten]]]
 * [[[neue-seite-anlegen | Neue Seite anlegen]]]
 * [[[system:join| Site Mitglied werden]]]
* [[[forum:start | Forum]]]
 * [[[forum:start | Gruppen-Übersicht]]]
 * [[[forum:recent-posts | Neueste Post]]]
 * [[[forum:minirecent-threads | Neueste Threads]]]
[[module ListPages category="buchecke" separate="no" prependLine="* [[[start-buchecke | Buchecke]]]"]]
[!-- --]
 * %%linked_title%%
[[/module]]
* [# Hilfe]
 * [*http://www.wikidot.com/doc Documentation]
 * [*http://www.wikidot.com/doc:wiki-syntax wiki-syntax]
 * [*http://community.wikidot.com/howto:howto-list How-To's]
 * [*http://handbook.wikidot.com/  HANDBUCH]
 * [[[How to edit pages?]]]
* [# Internals]
 * [[[system: Recent changes]]]
 * [[[system: List all pages]]]
 * [[[admin:manage|Site Manager]]]
* [[[contact]]]

In action

Easy to show..I used above code on a public site Turnen at bp:
have a look on the top nav menu point "Buchecke" - the entries are build automatically with the code inserted above!


Thanks to tsangk for this great snippet: conditional-blocks


text above inserted with:

[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]



Other snippets posted by Helmut_pdorf

Todo List with Data Forms - 30 Apr 2015 14:59
Html(embed) code opening in new window/tab - 29 Oct 2014 09:05
Facebook Button - 27 Dec 2013 15:03
Sorted-ListPages-List - 19 Aug 2013 15:56
Advanced Search - 25 Feb 2012 12:29
Schedules - 16 Feb 2012 01:40
Use any html code on a page - 16 Feb 2012 01:34
Find untagged pages - 15 Feb 2012 00:52


Rate this solution

If you think this solution is useful — rate it up!

rating: +15+x
Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License