• Hi.

    I’m trying to use wordpress as a basic CMS. In a page, let’s say ../teachers/ I’d like to display a list of all the teachers Smith, Calhoun, Johnson… (each of them is a sub-page of /teachers/ with their resume) with an excerpt or the first 50 to 100 words.
    the tag wp_list_pages displays only the slug or the title of the page…

    thanks,

Viewing 6 replies - 1 through 6 (of 6 total)
  • I’m a little lost…you define what you’re trying to do, but where is the question? At what point do you have a problem setting this up?

    yeah read the post like 5 times but still I cant make a fiddle out of this…

    You have sub-pages of a “parent” page teacher
    So
    Teacher ->
    Calhoun
    Johnson ….
    etc.

    And you want to view the first 50 words of those sub-pages ??

    Thread Starter krd

    (@krd)

    Sorry!

    I have sub-pages of a “parent” page.
    I want to view a summary of the sub-pages on the parent page.

    My problem is that I can’t figure how to use the Loop or ‘the_content’ or ‘the_excerpt’ to get pages excerpts.

    Uh, hmm. Pages are not handled in the same manner as posts, and can’t be looped in succession–not through the normal Loop process, that is. What I’d suggest (unless someone has a better solution) is to construct a database query that assigns Pages, but only those under the specific Page parent, to an array handled through the older (pre-1.5) Loop method. Here’s how you can do that…

    First, keep the regular Loop in your template, but within it use only this:

    <?php $pageID = $post->ID; ?>

    Here you’re capturing the Page ID number for your next step. (You can skip this and remove The Loop entirely if you hardcode the ID number of the parent Page into your sql query. I’m just making it a bit more flexible.) After the regular Loop ends, set up your customized one:

    <?php
    $posts = @$wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_status='static' AND post_parent='$pageID' ORDER BY post_date DESC");
    if($posts) : foreach($posts as $post) : start_wp();
    ?>

    At this point put the template tags and any HTML you want to use for the content of individual Pages:

    <div class="ChildPagesExample">
    <h3><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h3>
    <?php the_excerpt(); ?>
    </div>

    Then just close up your custom Loop:

    <?php endforeach; endif; ?>

    Note: You can change the order Pages are displayed by altering the ORDER BY portion of your sql query. Some options:

    ORDER BY post_date ASC
    Orders by post date, oldest to newest.

    ORDER BY ID
    Orders by post/Page ID.

    ORDER BY ID DESC
    Orders by post/Page ID, newest to oldest.

    ORDER BY post_name
    Orders by post name, alphabetically (A-Z).

    Thread Starter krd

    (@krd)

    Thank you very much, your solution is EXACTLY what I was looking for.

    There is only a small problem in the sidebar. Individual pages titles aren’t displayed :
    Warning: Invalid argument supplied for foreach() in /home/..WITHDRAWN../public_html/krd/wp-includes/template-functions-post.php on line 368
    But I do not really need them here.

    Once again, thank you !

    I have written a tutorial that should do this without using the Loop wrapper objects and also using a cache mechanism so there is not a database call every single time someone hits your page here integrate wordpress no loop with cache

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Displaying sub pages excerpts or first 50 words in a page’ is closed to new replies.