• Could use some help… using this code to call up a custom number of posts from a certain category a few times. I only want to display the first 15 or so words… However, it is showing the same excerpt (or a random one) on each post versus showing the unique excerpt for each post. Can anyone help me out on this one? The permalink, title and thumbail are all working/diplaying but the Code below is resulting in the same excerpt to be added to the posts

    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 } ?>

    This is on the page multiple times

    and my function.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('<code>\[[^\]]*\]</code>','',$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;
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Excerpt of Posts posting wrong excerpts….’ is closed to new replies.