Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Mikko Saari

    (@msaari)

    You need to edit the search results template. See the_post_thumbnail(). Relevanssi doesn’t have anything to do with whether the images are shown or not.

    Thread Starter LouisIsMyDog

    (@louisismydog)

    I figured it out. You just need to create a function like this and add it to your functions.php in your child theme.

    function attachments_search_the_excerpt( $excerpt ) {
      if ( ! is_search() ) {
      	return $excerpt;
      }
      $id = get_the_ID();
      if ( ! $id ) {
        return $excerpt;
      }
      if(get_post_type($id) != 'attachment') {
      	return $excerpt;
      }
    
      $caption = wptexturize( get_post($id)->post_excerpt );
      $image_url = wp_get_attachment_image_src( $id , 'full' );
      $thumbnailURL = $image_url[0];
      $image = aq_resize($thumbnailURL, 260, false);
      if(empty($image)) { $image = $thumbnailURL; }
    
      // compile output with thumbnail image
      $output = "<div id='attachment_{$id}' class='wp-caption aligncenter' >";
      $output .= "<img src='".esc_url($image)."' class='iconhover' style='display:block;'>";
      $output .= "<p class='wp-caption-text'>$caption</p>";
      $output .= "</div>";
    
      return $output;
    }
    // hook our function to the filter
    add_filter( 'the_excerpt', 'attachments_search_the_excerpt');

    Then you have it ??

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Display Post attachment image’ is closed to new replies.