Skip to content

Instantly share code, notes, and snippets.

@gmaggio
Created July 25, 2014 01:58
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gmaggio/f3e036c69f6f66aa3a68 to your computer and use it in GitHub Desktop.
Save gmaggio/f3e036c69f6f66aa3a68 to your computer and use it in GitHub Desktop.
[Wordpress] Display Child Pages on the Parent Page (including the Parent Page itself)
<?php
/**
* Display Child Pages on the Parent Page
* (including the Parent Page itself)
*
* Sources:
* - http://codex.wordpress.org/Function_Reference/wp_list_pages
* - http://www.wpbeginner.com/wp-tutorials/how-to-display-a-list-of-child-pages-for-a-parent-page-in-wordpress/
* - http://www.svennerberg.com/2009/02/creating-a-submenu-in-wordpress/
*/
function my_list_child_pages() {
if (is_page()) {
global $post;
$args = 'echo=0&sort_column=menu_order&title_li=';
// Check whether page is parent/child page
$page = ($post->post_parent) ? $post->post_parent : $post->ID;
$parent = wp_list_pages( $args.'&include='.$page );
$children = wp_list_pages( $args.'&child_of='.$page );
// If the current page has/is child page
$list = ($children) ? '<ul>'.$parent.$children.'</ul>' : '';
}
echo $list;
}
@brou1973
Copy link

Hi, I try to use your script but since I'm new in the world of WP, I don't know how to use it.
Could you guide me please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment