WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] the_excerpt() shows content images

[Resolved] the_excerpt() shows content images

  • I have an excerpt code for a page which shows a list of all posts:

    <?php $cat_title = single_cat_title('',false);
      if (!$cat_title=='') {
       if ( !empty($categorydesc) ) echo apply_filters( 'archive_meta', '<div class="archive-meta">' . $categorydesc . '</div>' ); } ?>
    <?php if(is_single()) {
      $category = get_the_category();
        query_posts('category_name=' . $category[0]->cat_name);
         } else {
          query_posts('category_name=' . single_cat_title(false, false)); }
            while (have_posts()) : the_post(); ?>
    <?php $content = preg_replace("/<img[^>]+\>/i", "", $content); ?>
    <div class="with_thumb"><a>"><?php the_title(); ?></a><?php the_time('d/m/y') ?><div id="post_excerpt"><?php the_post_thumbnail(); ?><?php the_excerpt(); ?></div>
    </div>
    <?php endwhile; wp_reset_query(); ?><br style='clear:both;' />

    This is the excerpt codes in the function.php:

    // excerpt
    add_filter( 'the_excerpt', 'excerpt_thumbnail' );
    function excerpt_thumbnail($excerpt){
        if(is_single()) return $excerpt;
        global $post;
        if ( has_post_thumbnail() ) {
            $img .= '<a>ID).'">'.get_the_post_thumbnail($post->ID, 'custom_thumb').'</a>';
        } else {
            $img = '';
        }
        return $img.$excerpt;
    }
    
    // custom excerpt length
    function custom_excerpt_length($length) {
    	return 20;
    }
    add_filter('excerpt_length', 'custom_excerpt_length');
    
    // no more jumping for read more link
    function no_more_jumping($post) {
    	return ' <strong><a>ID).'" class="read-more"> '.' Continue Reading'.'</a></strong>';
    }
    add_filter('excerpt_more', 'no_more_jumping');

    My problem is that the thumbnail shows and the first content image also shows along with it. I want to be able to show only the thumbnail and none of the content images. I’m not sure what I am doing wrong here.

    [please mark any posted code using the code button – http://codex.wordpress.org/Forum_Welcome#Posting_Code – the above code is already partly corrupted]

Viewing 3 replies - 1 through 3 (of 3 total)
  • Can’t tell for sure, but it looks like you are putting in the thumbnail twice, once in this line from the first bit of code:

    <div class="with_thumb"><a>"><?php the_title(); ?></a><?php the_time('d/m/y') ?><div id="post_excerpt"><?php the_post_thumbnail(); ?><?php the_excerpt(); ?></div>
    </div>

    and once from the excerpt_thumbnail function on this line:

    if ( has_post_thumbnail() ) {
            $img .= '<a>ID).'">'.get_the_post_thumbnail($post->ID, 'custom_thumb').'</a>';

    Okay will try to remove that line then to test.
    Thanks.

    Tested and it was the functions.php that was making the big image…
    I just don’t understand why it is automatically sized to maximum…
    Okay worked it out.
    Thanks…

    resolved

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] the_excerpt() shows content images’ is closed to new replies.
Skip to toolbar