WordPress.org

Support

Support » How-To and Troubleshooting » List sub pages – problems: displays all pages and subpages

List sub pages – problems: displays all pages and subpages

  • Hi! I´m trying to list my subpages in the sidebar. I want to list the current page and his child pages when the page has child pages (or I am in the child page).

    There´s plenty of information of how to do that, including in the codex:

    http://codex.wordpress.org/Function_Reference/wp_list_pages

    I´m usin this code:

    <?php
    if($post->post_parent)
    	$children = wp_list_pages("title_li=&child_of=".$post->post_parent."&echo=0");
    else
    	$children = wp_list_pages("title_li=&child_of=".$post->ID."&echo=0");
    if ($children) { ?>
    	<ul>
    		<?php echo $children; ?>
    	</ul>
    <?php } ?>

    But, when using this code, what I get is the display of all the pages with their supages.

    Any idea what´s going wrong? any suggestion?
    Anybody had the similar problem?

    I try a lot of different codes, and I´m having always the same problem, so I guess I´m doing something wrong when adding pages (my main pages has no superior, and my child pages have their respective parent page as superior, is that ok?)

    Finally, If I used any of the plugins for listing subpages it works correctly and the subpages are display as expected. However, I would like to do it without plugins, and especially, I would like to know why that code is not working for me.

    Thanks in advance!
    Víctor

  • The topic ‘List sub pages – problems: displays all pages and subpages’ is closed to new replies.
Skip to toolbar