• Resolved SpidermanPuddin

    (@spidermanpuddin)


    I am trying to get a code working that will display the title and excerpt from one parent page. So far I’ve got the titles to display Every Page from another post I found. Here’s what I’ve got:

    <?php
    $pageChildren = get_pages('sort_column=menu_order&amp;hierarchical=0&amp;child_of='.$post->ID);
    if ( $pageChildren ) {
      foreach ( $pageChildren as $pageChild ) {
        echo 'And the title is: '. $pageChild->post_title.'
    ';
        if ($pageChild->post_excerpt){
          echo 'And the excerpt is: '.$pageChild->post_excerpt.'
    ';
        if (!empty($pageChild->post_excerpt)){
    	echo '<a href="' . get_permalink($pageChild->ID) . '">' . $pageChild->post_excerpt.'</a>
     ';
    }
        }
      }
    }
    ?>

    I need it to display all the posts under the page “how-to” or id “390”.

Viewing 11 replies - 1 through 11 (of 11 total)
  • Hi

    Not clear what you mean by display all the posts under the page “how-to”

    Posts are not under pages. Posts can be assigned to categories or tags but not to pages. you can DISPLAY posts on a page, but that does not mean they are under that page.

    can you explain more clearly what you want to do?
    thanks

    Thread Starter SpidermanPuddin

    (@spidermanpuddin)

    I meant pages.

    I’m trying to list the Title and Excerpt of all the Child Pages under a Parent Page.

    I think if you change this
    &amp;child_of='.$post->ID);
    to this
    &amp;child_of=390';

    you should be good to go

    Thread Starter SpidermanPuddin

    (@spidermanpuddin)

    It’s still displaying all of the Pages. Also it’s not displaying any excerpts.

    <?php
    $pageChildren = get_pages('sort_column=menu_order&amp;hierarchical=0&amp;child_of=390');
    if ( $pageChildren ) {
      foreach ( $pageChildren as $pageChild ) {
        echo 'And the title is: '. $pageChild->post_title.'
    ';
        if ($pageChild->post_excerpt){
          echo 'And the excerpt is: '.$pageChild->post_excerpt.'
    ';
        if (!empty($pageChild->post_excerpt)){
    	echo '<a href="' . get_permalink($pageChild->ID) . '">' . $pageChild->post_excerpt.'</a>
     ';
    }
        }
      }
    }
    ?>

    You are sure the page parent is ID 390.

    If you use just get_pages('child_of=390'); what happens?

    Thread Starter SpidermanPuddin

    (@spidermanpuddin)

    That worked perfect now how do I get the excerpt part to work? And is there a way to limit the number of pages shown to the 2 latest?

    <?php
    $pageChildren = get_pages('child_of=390');
    if ( $pageChildren ) {
      foreach ( $pageChildren as $pageChild ) {
        echo 'And the title is: '. $pageChild->post_title.'
    ';
        if ($pageChild->post_excerpt){
          echo 'And the excerpt is: '.$pageChild->post_excerpt.'
    ';
        if (!empty($pageChild->post_excerpt)){
    	echo '<a href="' . get_permalink($pageChild->ID) . '">' . $pageChild->post_excerpt.'</a>
     ';
    }
        }
      }
    }
    ?>

    Thread Starter SpidermanPuddin

    (@spidermanpuddin)

    Also just noticed this… Need a Link on there. :-/

    Pages do not have excerpts so your tests for the existence of such will fail.

    Might look for a plugin that allows you to enter an excerpt for a page.

    Thread Starter SpidermanPuddin

    (@spidermanpuddin)

    Thanks for the help MichaelH and stvwlf.

    Here’s the coded I ended up with.

    <?php
    $pageChildren = get_pages('child_of=390');
    if ( $pageChildren ) {
      foreach ( $pageChildren as $pageChild ) {
        echo '<h2><a href="' . get_permalink($pageChild->ID) . '">'. $pageChild->post_title.'</a></h2>
    ';
        if ($pageChild->post_excerpt){
          echo ''.$pageChild->post_excerpt.'
    
    ';
        }
      }
    }
    ?>

    I had to download the plugin Page Excerpt which did the job.

    Dougal

    (@dougalcrowder)

    Thanks for this code, works well.
    Does anyone know how to add the_post_thumbnail to this? Would be really helpful. Cheers

    Many thanks SP, your code was exactly what I needed. I am also using Page Excerpt.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Display Title and Excerpt of Sub-Pages’ is closed to new replies.