• Resolved knightkato

    (@knightkato)


    Hejhej,

    I’m trying to do exactly what the title suggests, list excerpts of the child pages on the parent page. I’ve added excerpts to the pages by installing pjw_page_excerpt plugin, that works nicely.

    And I’ve found this code for getting it,

    <? $pageChildren = $wpdb->get_results("SELECT *	FROM $wpdb->posts WHERE post_parent = ".$post->ID."	AND post_type = 'page' ORDER BY menu_order", 'OBJECT');	?>
    <? if ( $pageChildren ) : foreach ( $pageChildren as $pageChild ) : setup_postdata( $pageChild ); ?>
    <!-- loop stuff here -->
    <? endforeach; endif; ?>

    But this doesn’t work (i think its for a previous version of wp)

    Any ideas on how to do this..?

Viewing 5 replies - 1 through 5 (of 5 total)
  • How about this:

    <?php
    $pageChildren = get_pages('sort_column=menu_order&hierarchical=0&child_of='.$post->ID);
    if ( $pageChildren ) {
      foreach ( $pageChildren as $pageChild ) {
        echo '<p>And the title is: '. $pageChild->post_title.'</p>';
        if ($pageChild->post_excerpt){
          echo '<p>And the excerpt is: '.$pageChild->post_excerpt.'</p>';
        }
      }
    }
    ?>
    Thread Starter knightkato

    (@knightkato)

    Thanks MichaelH,

    It works for the title but not for the excerpt, i’d also need to get the permalink surrounding the excerpt, but maybe that’s it’s outputted by default. (I think so)

    I’m guessing it has something to do with wp’s way of dealing with page excerpts, but they do exist in the database, so it should be fine.

    Thread Starter knightkato

    (@knightkato)

    Correction, its working if I take away the if ($pageChild->post_excerpt){ line,

    could i get the permalink by the same method?

    as in, echo '<a href="$pageChild->perma_link'"> '.$pageChild->post_excerpt.'</a>'; ?

    Try this segment:

    if (!empty($pageChild->post_excerpt)){
    echo '<p><a href="' . get_permalink($pageChild->ID) . '">' . $pageChild->post_excerpt.'</a> </p> ';
    }
    Thread Starter knightkato

    (@knightkato)

    Works perfectly! Thanks a bunch, saved my day.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘List excerpts of Child pages on the Parent page.’ is closed to new replies.