You are here

Pet menu children

Submitted by Peter on Thu, 2010-05-06 15:02

The Pet menu children module for Drupal lists the children of a page in the current menu using token . There is also an option to list the children of other pages.

After you install the module, you add tokens in the form . The token is replaced by an unordered list of node titles and teasers.

Pages are based on nodes within the Drupal content management system. For our purposes, a page is a node and a node is a page. We are adding a list of page summaries, called teasers in Drupal, to a page. The main part of the page content is a node. The Pet menu children token is in the node content shown on the page. We work from the node containing the token to the menu entry for the node, or page, and find the children of the menu entry. We then list the title and teaser (summary) of each node (page) in the same sequence as used in the menu.

You can alter the sequence of entires in the menu to put important items first. the should appear in the same sequence in the Pet menu children list.

The module finds the current node in the menu then lists the children of the current node. Drupal 6 has three menus and Drupal 7 lets you define your own. Pet menu children looks for children within the same menu as the parent menu entry.

Children of other pages

Visit page Speed for an example of an extended token. In the example page, the General software list is generated from the following token.

The Content Management Systems list is generated from the children of another page using the following token containing the page title.

Formatting the output

There are classes and ids for formatting the list. The following code is the HTML generated for one entry in the list.

<ul id="pet-menu-children-313" class="pet-menu-children pet-menu-children-pet">
<li><a class="pet-menu-children-link" href="pet_menu_children"><strong>Pet menu children</strong></a><br />
<p>The Pet menu children module for <a href="/drupal">Drupal</a> lists node children from the menu through token <strong></strong>. <a class="pet-menu-children-read-more-link" href="pet_menu_children"><em class="pet-menu-children-read-more">Read more about Pet menu children...</em></a></p></li>
</ul>

Code

Use the contact form to request the code. I occasionally refine it for my use and mention the changes here.

The latest change is to make the paragraph element conditional to avoid duplicates. The code inserts a HTML paragraph element around the teaser for formatting. If there is already a paragraph element at the start of the teaser, the extra paragraph is not added.