Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I just can't win with this project! All of a sudden, each post's gallery photos are showing up in the excerpt/preview of the post. Each post has a gallery of images that should only be visible on the actual post's page. Can anyone see what might be causing this?

Here is my code:

if ( has_post_thumbnail() ) {
     the_post_thumbnail();
}
else {
     get_the_image( array('size' => 'thumbnail',
                          'image_class' => 'wp-post-image'));   
}

Then in my functions file:

// This theme displays custom size (page-single) featured image on the Post's  page

function InsertFeaturedImage($content) {

    global $post;

    $original_content = $content;

    if ( current_theme_supports( 'post-thumbnails' ) ) {

        if ((is_page()) || (is_single())) {

            $content = get_the_image( array( 'size' => 'full' ) );
            $content .= $original_content;
        }
    }
    return $content;
}

add_filter( 'the_content', 'InsertFeaturedImage' );

You can view the site in question here: http://dependablecarcompany.com

You'll see the horribly broken site in question. There should only be the ONE excerpt representative thumbnail there, and not all the thumbs from the gallery too.

Thank You!

share|improve this question
    
Thank you for your reply peter! I'm trying to use this, but I'm getting a syntax error, now. I will keep trying to figure it out though. –  Anthony Myers Aug 3 '12 at 14:53

2 Answers 2

up vote 1 down vote accepted
   if(  ( is_page() || is_single() ) && ( !is_home() &&  !is_front_page() )  ){
        $content = strip_shortcodes( $original_content); 
    }

if its home or front page don't show gallery

    if( is_home() || is_front_page() ) {
          // don't show gallery
          $content = strip_shortcodes( $original_content); 
    } else {
          $content = get_the_image( array( 'size' => 'full' ) );
          $content .= $original_content;
    }

The post was using shorttags to print the gallery, get_the_image() printed the thumbnail.

so by removing the shorttags from appearing in the front page, the gallery no longer is shown on it, but will show on other pages, and also, categories, tags etc.

To further improve on that, add || is_archive() to the conditional above.

reference for is_home() and strip_shortcodes()


just for fun:

truth table:

  • 0 0 0 1 = ( 0 || 0 ) && ( 1 && 0 ) = 0 && 1 = 0
  • 0 0 1 0 = ( 0 || 0 ) && ( 0 && 1 ) = 0
  • 0 0 1 1 = 0
  • 0 1 0 0 = 0
  • ... = 0
  • 1 0 0 0 = 1
  • 0 1 0 0 = 1
  • 1 1 0 0 = 1
  • ... = 0
  • share|improve this answer
        
    Is there a way to say if is_home or if is_front_page then don't display the gallery thumbnails? –  Anthony Myers Aug 4 '12 at 20:07
        
    yes, more or less, but yes. i've updated the response. –  peteroak Aug 4 '12 at 20:50
        
    dangit! haha, I can't get anything to work without throwing syntax errors. Should I be trying to combine both of those code blocks together as one? In other words, do I combine the is_single is_home code block with the new is_font_page is_home code you just posted? Thanks! –  Anthony Myers Aug 4 '12 at 21:06
        
    there you go, all nice and done ;) –  peteroak Aug 4 '12 at 21:13
        
    Thanks a ton for your time peter! Just doesn't fix the problem though. So weird. I've tried so many things and the stupid gallery photos are showing on the home page no matter what. I appreciate you trying though. –  Anthony Myers Aug 4 '12 at 21:22

    Myers.

    I guess you have this code on your index.php file or whathever file displaying content in homepage:

    if ( has_post_thumbnail() ) {
     the_post_thumbnail(); 
    } else {
     get_the_image( array('size' => 'thumbnail',
                          'image_class' => 'wp-post-image'));   
    }
    

    I had tested in mine. I do not use the code above. I only use this in functions.php

    // This theme displays custom size (page-single) featured image on the Post's  page
    
    function InsertFeaturedImage($content) {
    
    global $post;
    
    $original_content = $content;
    
    if ( current_theme_supports( 'post-thumbnails' ) ) {
    
        if ((is_page()) || (is_single())) {
    
            $content = get_the_image( array( 'size' => 'full' ) );
            $content .= $original_content;
        }
    }
    return $content; 
    }
    add_filter( 'the_content', 'InsertFeaturedImage' );
    
    share|improve this answer
        
    Thanks for your recommendation. It still does the same thing though. I don't want any of the gallery thumbs to show at all, on the home page. –  Anthony Myers Aug 4 '12 at 19:52

    Your Answer

     
    discard

    By posting your answer, you agree to the privacy policy and terms of service.

    Not the answer you're looking for? Browse other questions tagged or ask your own question.