Word Press Child Page menu

Creating a sidebar menu using Child Pages in WordPress

Trying to find the correct syntax to display a sidebar menu that shows all the “Child Pages” along with a custom title can be challenging.

Syntax

<li> <?php wp_list_pages(‘child_of=10&title_li=<h2>’ . __(‘Your Custom Menu Title Here’) . ‘</h2>’); ?></li>

Breaking down the code

<li> </li> This is the beginning and ending HTML tags for a “List Item”. The list item tag is used for all menu items.

<?php> <?> This is the starting and ending tags of a PHP statement.

wp_list-pages This is the predefined WordPress function that brings queries the pages.

( ) Everyting between the brackets holds the arguments for the WordPress function. In this example we are using two arguments that are sperated by the “&” symbol.

child_of=10 This is the first argument for our wordpress function. The parameter “child_of” displays the child and grandchildren pages of a single Page only. The number following the “=” sign (Shown with the number 10) represents the Parent Page ID. Note: The parameter “child_of” does not display the Parent Page.

& This is the PHP code to join arguments.

title_li=<h2>’ . __(‘Your Custom Menu Title Here’) This is the prameter used to display a custom heading for your child page menu. I will break this code down further.

title_li= This is the second argument for our wordpress function which sets the title for our page menu.

<h2> sets the font style for the menu. The ending tag happens at the end of this argument.

. __(‘Your Custom Menu Title Here’) Sets the text of the Page menu. The default is '__('Pages')', which displays “Pages”. Simply edit the text between the single quotation makes.

. ‘</h2>’) This ends our statement and also closes the <h2> header tag from earlier.

Child Menu Summary

Once you look at the different elements of this statement if becomes quite easy to understant that is happening in each section. For a complete listing of please visit the WordPress.org wp_list-pages site.

Thank you for visiting my site and let me know if you found this to be useful.

Leave a Comment