Ready to get started?Download WordPress


Display children of current page (2 posts)

  1. chris.sorel
    Posted 2 years ago #

    I have looked high and low for this. What I am trying to do is display the child objects of the current page on the page. All I am looking to do is show just the children in a list on the same page. What I am looking for is a php function that will pull the current page and list the children of it without any user intervention. I am currently using PHP-Exec plugin which allows me to input php directly into my pages on my site. I would like to have this so that a user can copy an past it right into the page and not have to enter anything into it like the page ID. What I currently have is below. At the moment I have to enter the page id manually for it to work. I would like that info to be just pulled and inputted into the function. Sorry if I am referring to things incorrectly here I am a bit of a n00b. The simpler the better. I would like to replace the page id in the child_of= attribute with a variable that contains the page id pulled from the page itself but I don't know how to do it. Any help would be greatly appreciated.

    <ul style="list-style-type: none">
    <?php wp_list_pages( 'child_of=33&title_li=&depth=1'); ?>
  2. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    consider to create a shortcode http://codex.wordpress.org/Shortcode_API

    for example, add the following into functions.php of your theme:

    function show_page_children_list( $atts ){
      global $post;
      $return = '<ul style="list-style-type: none">';
      $return .= wp_list_pages( 'child_of='.$post->ID.'&title_li=&depth=1&echo=0');
      $return .= '</ul>';
     return $return;
    add_shortcode( 'children', 'show_page_children_list' );


    then simply add [children] into the page content where you want your child pages list.

Topic Closed

This topic has been closed to new replies.

About this Topic