WordPress.org

Support

Support » Plugins and Hacks » Hacks » [Resolved] Excerpt … the loop? recent posts on another page besides the blog page…

[Resolved] Excerpt … the loop? recent posts on another page besides the blog page…

  • AaronRhoades

    @aaronrhoades

    I have a website. http://www.aaronrhoades.com/blog is where it’s at right now (will be moving it to http://www.aaronrhoades.com when it’s done).

    I’m trying to get the little thing on the upper right corner to work. EVERYTHING IS PERFECT… EXCEPT…. the excerpt is from the home page, rather than from each individual post… how do I fix it?

    <?php
    	$args = array( 'numberposts' => '4' );
    	$recent_posts = wp_get_recent_posts( $args );
    	foreach( $recent_posts as $recent ){
    		echo '<li><h3><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"]. "</a></h3>" . get_the_excerpt() . "</li>" ;
    	}
    ?>

    I need them to be list items. I think the problem, lies in “get_the_excerpt” which I had tried using the_excerpt, but that didn’t work either. how do i specify where to grab the excerpt? not sure if I’m in the wrong direction.

Viewing 2 replies - 1 through 2 (of 2 total)
  • You can use $recent[“post_excerpt”] instead of get_the_excerpt().

    This only works if you have a custom excerpt. Otherwise you’d have to use substr() in conjunction with $recent[“post_excerpt”] to get the desired string.

    Moderator bcworkz

    @bcworkz

    Right, get_the_excerpt() only works inside a standard WP “Loop”, not any arbitrary PHP looping structure.

    you’d have to use substr() in conjunction with $recent[“post_excerpt”] to get the desired string.

    I presume Mr. Jones meant $recent["post_content"].

    As an alternate to substr() and it’s related string manipulation functions, you could do what WP does and get an automatic excerpt with wp_trim_excerpt().

    I posted the above suggestion, thinking the function was passed the content. Upon reviewing the link provided, it mentions that passing content does not have the desired effect. Something smelled funny. On further investigation, even though the Function Reference makes no mention, this function must also be used in a standard WP “Loop”.

    So never mind, substr() it is. I’m going to append the Function Reference.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Excerpt … the loop? recent posts on another page besides the blog page…’ is closed to new replies.
Skip to toolbar