Hand-crafting Excerpts for Pages got a lot easier in in WordPress 3+. Put this in your functions.php
:
[php]add_post_type_support( ‘page’, ‘excerpt’ );[/php]
And voilà , an Excerpt textarea
should now show on your Edit Page screen (make sure “Excerpt” is checked in Edit Page»Screen Options). To extract Pages’ Excerpts…
Inside a WP loop (e.g., query_posts()), you can use the_excerpt()
(or the_excerpt_rss()
):
[php htmlscript=”true”]<?php query_posts( ‘post_type=page’ );?><br />
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?></p>
<h3><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h3>
<p> <?php the_excerpt(); ?><br />
<?php endwhile; else: ?></p>
<p>Yer lame-ass Loop is Post-less.</p>
<p><?php endif; ?>[/php]
Outside the loop, get_pages()
will git ‘er done:
[php htmlscript=”true”]<?php<br />
$pages = get_pages();<br />
foreach ( $pages as $page ) : ?></p>
<h3><a href="<?php echo get_page_link($page->ID); ?>"><?php echo $page->post_title; ?></a></h3>
<p><?php echo $page->post_excerpt; ?></p>
<p><?php endforeach; ?>[/php]
Both the above output about the same HTML. To access a single Page’s Excerpt, get_page()
already has a post_excerpt
parameter:
[php]<?php $n = 420; echo( get_page($n)->post_excerpt ) ?>[/php]
Note: you gotta pass a variable into the above function, else WP will freak. As decreed in the esteemed Codex:
“You must pass in a variable to the get_page function. If you pass in a value (e.g.
get_page(123);
), WordPress will generate an error.”
Apparently a Page Excerpt panel was once part of WP’s past. Well, they’re back, baby.
via mfields.