In the code below represents a link list of recent posts. I’m just trying to write out the post name, along with the post excerpt if one exists. So I’m using the get_link_excerpt($post) function in order to determine if the current post in the for loop has an excerpt.
It works fine if the post has an excerpt, however, if it doesn’t, the get_the_excerpt() function is returning its own excerpt crafted from the current page’s content.
In this case, I’m placing this function on the home page, so every post that does not explicitly have a snippet is getting a virtual excerpt from the home page’s content.
Apparently, I’m passing $post improperly, what’s the correct way to do it here?
function show_footer_recent(){
$myquery = new WP_Query();$myquery->query(array('post__not_in' => get_option('sticky_posts')));
$myrecentpostscount = $myquery->found_posts;
if ($myrecentpostscount > 0){ ?>
<div>
<ul><i>Latest News & Articles</i>
<?php global $post;$myrecentposts = get_posts(array('post__not_in' => get_option('sticky_posts'),'numberposts' => get_option('cb2_recent_count')));
foreach($myrecentposts as $idxrecent=>$post) { ?>
<li class="page_item">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a><?php echo get_link_excerpt(); ?>
</li><?php } ?>
</ul>
</div>
<?php }}
function get_link_excerpt(){
$LinkExcerpt = strip_tags(substr(get_the_excerpt(), 0, 75 ));
if($LinkExcerpt != '')
{
return ": ".$LinkExcerpt."...";
}
return false;
}
I got it working. Here’s what I had to do in my utility function…