• Resolved tee05

    (@tee05)


    Hi, I was wondering if someone could help me get the following code working. Basically, I’m using the wp_list_pages() array code to get the parameters of ‘child_of’ ID. (I’m using this code because I’d like to list the pages without the use of list tags <li></li>). So far it’s worked fine expect when I try to display the child pages of a parent page it doesn’t seem to pick up the ID correctly. Here’s the code:

    $args = array(
    'post_type'   => 'page',
    'child_of'    => 2, // Problem Here
    'echo'        => 1,
    'sort_column' => 'menu_order',
    'depth'       => 0,
    );              
    
    $pages = get_posts($args);
      foreach($pages as $page) {
    	  $out .= '';
    	  $out .=  '<a href="'.get_permalink($page->ID).'" title="'.wptexturize($page->post_title).'">'.wptexturize($page->post_title).'</a>';
      }
    $out = '' . $out . '';
    echo $out;
Viewing 2 replies - 1 through 2 (of 2 total)
  • MichaelH

    (@michaelh)

    Consider using get_pages() instead of get_posts().

    Thread Starter tee05

    (@tee05)

    Thank you that helped! Incase anyone else needs this code:

    <?php
    	$pages = get_pages('child_of=2&sort_column=post_date');
    	$count = 0;
    	foreach($pages as $page)
    	{
    	?>
    		<a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a>
    	<?php
    	}
    ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘wp_list_pages() child_of not working’ is closed to new replies.