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] <?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> <!– END CUSTOM PAGE EXCERPTS CODE –> [/php]
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!
Joni Mueller has been designing web sites for hire since 2003, when she first blew up her web host’s server by insisting on running Greymatter. Since then, Joni has designed for Blogger and Movable Type, TextPattern, WordPress and CMS Made Simple. She lives with her cat and shoe collection in a bucolic old section of Houston called Idylwood. For some strange reason, Joni likes to refer to herself in the third person. When she’s not working on web design, she’s ordering lawyers around. And blogging about it. Or both.