Now you wouldnâ€™t normally need to display an excerpt from a pageâ€™s description, would you? I didnâ€™t think so either. But apparently there is a need. And when thereâ€™s a need, we aim to please. We had a client who wants to display custom excerpts from a pageâ€™s child pages on the parent page with links to the child page. WordPress normally doesnâ€™t excerpt from pages, only from posts.
So we had to find a plugin that would do that. Enter PJW Page Excerpt by Peter Westwood. Once you install this plugin, thereâ€™s nothing to configure. You just go to the page where you want to add an excerpt and youâ€™ll notice an excerpt box just like youâ€™d see on a post entry page. How cool is that?
The next step is to add your custom excerpts to all your pageâ€™s child pages. Then watch the magic.
<?php if (have_posts()) : while (have_posts()) : the_post(); ?> <div class="post" id="post-<?php the_ID(); ?>"> <?php $parent = $post->ID; ?> <h2 class="title"><?php the_title(); ?></h2> <?php the_content('<p>strong>Read the rest of this page »</strong>'); ?> <?php wp_link_pages(array('before' => '<p><strong>Pages:</strong> ', 'after' => '</p>', 'next_or_number' => 'number')); ?> <?php endwhile; endif; ?> <?php query_posts('post_type=page&post_parent='.$parent); ?> <ul class="about-excerpts"> <?php while (have_posts()) : the_post(); ?> <li> <span class="title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span> <?php the_excerpt(); ?> </li> <?php endwhile; ?> </ul>
Notice that Iâ€™ve added styling hooks to the unordered list. This is because I donâ€™t want a list-style-type, but rather a nice inline paragraph. And that lets me style the output however I want. Hope this helps someone else!