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 a script in archive.php, which is outside the loop, that calls on the function get_blog_links() to list all posts that belong the the current category (my "blog" category).

I'm trying to do some trace testing inside the "get_blog_excerpt() function in order to write out either the post excerpt or (if no excerpt appears) the first 55 words of content (the_excerpt) for each post.

However, I'm unable to obtain a reference to the_excerpt in my function.

Any help much appreciated.

//Blog Listing
function get_blog_links(){
    $myposts = get_posts();
    echo '<div>'; 
    echo '<ul>'; foreach($myposts as $idx=>$post){ ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  // THE FUNCTION CALL IM WORKING ON...
            <?php echo get_blog_excerpt();?></li>
    <?php } 
    echo '</ul></div>';
}


function get_blog_excerpt(){
    // return get_the_excerpt(); WORKS
    // return the_permalink();  WORKS
    // return the_excerpt(); DOES NOT WORK?
    // return get_the_content(); DOES NOT WORK?
}
share|improve this question

1 Answer 1

up vote 1 down vote accepted

I think you have to setup_postdata() with get_posts() to get things that rely on global variables to work. or explicitly pass the post id with the function.

share|improve this answer
    
That's it Milo. setup_postdata() has got me on a couple of occasions. Memory is soft :-) Thanks! –  Scott B Jun 17 '11 at 18:58

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.