Could use some help... using this code to call up a custom number of posts from a certain categorey and only want to display the first 15 characters. However, it is showing the same excerpt on each post versus showing the unique excerpt for each post. Can anyone help me out on this one?
Code below is resulting in the same excerpt to be added to the posts, even though the correct title and thumbnails are displaying!
I'm a bit of a novice so if you can explain I'd gladly appreciate it!
<?php $posts = get_posts('category=3&orderby=date&numberposts=3'); foreach($posts as $post) { ?>
<a href="<?php the_permalink() ?>" target="_parent">
<div class="aligncenter" style="display: block;">
<?php the_post_thumbnail( 'thumbnail', array( 'class' => 'img-responsive' ) ); ?>
</div>
<h3><?php the_title(); ?></h3></a>
<?php while (have_posts()) : the_post(); ?>
<?php echo excerpt(15); ?>
<?php endwhile; ?>
<a href="<?php the_permalink() ?>" class="blue"" target="_parent">
Read More</a>
</div>
<?php } ?>
here is my functions.php
function excerpt($limit) {
$excerpt = explode(' ', get_the_excerpt(), $limit);
if (count($excerpt)>=$limit) {
array_pop($excerpt);
$excerpt = implode(" ",$excerpt).'...';
} else {
$excerpt = implode(" ",$excerpt);
}
$excerpt = preg_replace('`\[[^\]]*\]`','',$excerpt);
return $excerpt;
}
function content($limit) {
$content = explode(' ', get_the_content(), $limit);
if (count($content)>=$limit) {
array_pop($content);
$content = implode(" ",$content).'...';
} else {
$content = implode(" ",$content);
}
$content = preg_replace('/\[.+\]/','', $content);
$content = apply_filters('the_content', $content);
$content = str_replace(']]>', ']]>', $content);
return $content;