Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have enabled the excerpt feature for pages in my wordpress theme -

add_action( 'init', 'my_add_excerpts_to_pages' );
    function my_add_excerpts_to_pages() {
         add_post_type_support( 'page', 'excerpt' );
    }

This has enabled the excerpt box when adding or updating pages through the admin area, which is what I expected.

I am then trying to display each excerpt on the homepage of my site like so -

$child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent  = 64    AND post_type = 'page' ORDER BY post_title", 'OBJECT');    ?>
            <?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
            <div class="memberHover" id="member-<?php echo $pageChild->ID; ?>">
              <div><h4><?php echo $pageChild->post_title; ?></h4>
                <p><?php the_excerpt(); ?></p>
              </div><?php echo get_the_post_thumbnail($pageChild->ID, '312,156'); ?>
            </div>
        <?php endforeach; endif; ?>

The issue is that even if I have a manual excerpt populated through the admin area, it still creates the auto excerpt when displaying on the homepage. It seems that it is not picking up the fact that there is a custom excerpt in the database for each item.

Any and all help is greatly appreciated!

Thanks, Tristan

share|improve this question
    
does the manual excerpt work in posts? if not, then there could be a plugin conflict. –  Michael Feb 28 '12 at 13:29
add comment

3 Answers

up vote 2 down vote accepted

Because I am very particular about how to do things in Wordpress when it comes to looping, I couldn't help but want to post a better way to do the above loop in your question as seeing the way you've done it looks like a lot of unnecessary work for yourself.

You already answered your own question but for the sake of being able to use the function the_excerpt() I've rewritten the above code to work using the WP_Query object instead which I believe is a better way of going about loop related matters (not to mention easier). You really only need to use manual queries like that when you want to query something the WP_Query class cannot.

<?php
$args = array('post_parent' => 64, 'orderby' => 'title', 'order' => 'ASC', 'post_type' => 'page', 'post_status' => 'publish');
$child_pages = new WP_Query($args);
?>

<?php if ($child_pages->have_posts()): ?>

<?php while($child_pages->have_posts()): $child_pages->the_post(); ?>
            <div class="memberHover" id="member-<?php the_ID(); ?>">
              <div><h4><?php the_title(); ?></h4>
                <p><?php the_excerpt(); ?></p>
              </div><?php echo get_the_post_thumbnail($post->ID, '312,156'); ?>
            </div>
<?php endwhile; ?>

<?php endif; ?>
share|improve this answer
1  
Thanks very much :) I'll mark this as the answer instead. –  TGuimond Mar 1 '12 at 11:47
add comment

I've had this issue before. The way you handled it is correct, but you can also do this which is essentially the same, (but a little different):

<?php echo get_the_excerpt();?>
share|improve this answer
    
Thanks for the heads up. –  TGuimond Mar 8 '12 at 9:24
add comment

Fixed :)

I updated <p><?php the_excerpt(); ?></p> to be <p><?php echo $pageChild->post_excerpt; ?></p> and this solved the issue.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.