WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] the_excerpt() shows content images (4 posts)

  1. fja3omega
    Member
    Posted 1 year ago #

    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]

  2. vtxyzzy
    Member
    Posted 1 year ago #

    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>';
  3. fja3omega
    Member
    Posted 1 year ago #

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

  4. fja3omega
    Member
    Posted 1 year ago #

    resolved

Topic Closed

This topic has been closed to new replies.

About this Topic