Categories

Featured templates

WordPress. How to display a list of child pages for a parent page

Sarah Vaynbaum March 31, 2015
Rating: 3.7/5. From 3 votes.
Please wait...

Today you will learn how to display a list of child pages for a parent page in WordPress.

WordPress. How to display a list of child pages for a parent page

You should follow the steps below:

  1. Enter your cpanel/ftp and then follow this path: wp-content/themes/themeXXXXX/includes (you can also do that through admin panel, you need to open following menu: Appearence -> Editor), there you will find custom-function.php file where you need to add the following code:

    function my_list_child_pages() { 
    global $post;
    if ( is_page() && $post->post_parent )
     $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->post_parent . '&echo=0' );
      else
      $childpages = wp_list_pages( 'sort_column=menu_order&title_li=&child_of=' . $post->ID . '&echo=0' );
    if ( $childpages ) {
    $string = '<ul>' . $childpages . '</ul>';
    }
    return $string;
    }
    add_shortcode('my_childpages', 'my_list_child_pages');

    How to Display a List of Child Pages For a Parent Page in WordPress

  2. The above code first checks if a page has a parent or the page itself is a parent. If it is a parent page, then it displays the child pages associated with it. If it is a child page, then it displays all other child pages of its parent page. Lastly, if this is just a page with no child or parent page, then the code will simply do nothing. In the last line of the code we have added a shortcode, so you can easily display child pages without modifying your page templates. To display child pages, simply add the following shortcode in a page or text widget in the sidebar:

    [my_childpages]

    How to Display a List of Child Pages For a Parent Page in WordPress2

After re-loading the page you will be able to see the list of child pages. In case you need the detailed information, feel free to check the video version.

WordPress. How to display a list of child pages for a parent page

Custom Wordpress Themes
This entry was posted in WordPress Tutorials and tagged child, list, page, parent, WordPress. Bookmark the permalink.

Submit a ticket

If you are still unable to find a sufficient tutorial regarding your issue please use the following link to submit a request to our technical support team. We'll provide you with our help and assistance within next 24 hours: Submit a ticket