WordPress.org

Ready to get started?Download WordPress

Forums

getting excerpts of a blog (2 posts)

  1. OperaManiac
    Member
    Posted 7 years ago #

    <?php
    require('/<em>path</em>/wp-blog-header.php');
    ?>
    
     <?php
     $posts = get_posts('numberposts=5');
     foreach($posts as $post) :
     ?>
    <p><strong><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </strong></p>
    <?php the_excerpt(); ?>
     <?php endforeach; ?>

    I am using this code to get the latest 5 posts from a blog along with the excerpts from a blog.

    After upgrading to 2.1.1 I just get post link in the output not the excerpts. Any ideas?

  2. richsipe
    Member
    Posted 7 years ago #

    I believe your are missing a bit of code in your setup for the main loop.

    <?php foreach( $posts as $post ) : setup_postdata( $post ); ?>

    You need to add setup_postdata($post) to your loop.

    Then your exerpt should work as you have it:

    <?php the_excerpt(); ?>

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.