[resolved] Excerpt ... the loop? recent posts on another page besides the blog page... (3 posts)

  1. AaronRhoades
    Posted 2 years ago #

    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?

    	$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.

  2. Steven Jones
    Posted 2 years ago #

    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.

  3. bcworkz
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic