Support » Fixing WordPress » limiting subpages.

  • Hi,

    Immediatly after my Loop, in page.php, I am using the get_page() function to get the subpages of a current page. The code is as follows.

    <?php $pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&parent='.$post->ID.'&heirarchical=1');
    $count = 0;
    $more = 1;
    foreach($pages as $page) {
    	$content = $page->post_content;
    	if(!$content)
    		continue;
    	$count++;
    	$content = apply_filters('the_content', $content);
    ?>
    
    <a href="<?php echo get_page_link($page->ID) ?>"><h1 class="title"> <?php echo $page->post_title ?> </h1></a> <?php echo $content ?>
    <?php
        }
    ?>

    The problem I am having is that all the descendents of the current page are displayed, not just the immediate children.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Try changing this:

    <?php $pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&parent='.$post->ID.'&heirarchical=1');
    $count = 0;

    to this:

    <?php $pages = get_pages('parent=0&child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&parent='.$post->ID.'&heirarchical=1');
    $count = 0;
    Thread Starter mannyk29

    (@mannyk29)

    I made the change you suggested wirh no effect,

    However I did get the result I wanted by bruit force.

    <?php
    $more =1;
    $pages = get_pages('child_of='.$post->ID.'&sort_column=post_date&sort_order=desc&&heirarchical=1');
    $count = 0;
    foreach($pages as $page) {
    	$content = $page->post_content;
    	if(!$content)
    		continue;
    	$count++;
    	$content = apply_filters('the_content', $content);
    
    	// test to see if the child page is a first genneration child
    	if (get_parent_id($page->ID) == $post->ID) {
    ?>
    <a href="<?php echo get_page_link($page->ID) ?>"><h1 class="title"> <?php $page->post_title; ?> </h1></a> <?php echo $content; ?>
    <?php
    		}
        }
    ?>

    thanks again for your help

    Sorry it didn’t work. Please mark this topic ‘Resolved’.

    The solution mentioned by “vtxyzzy” worked for me. Thanks a lot.

    ..Sarthak

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘limiting subpages.’ is closed to new replies.