Support » Plugin: Yet Another Related Posts Plugin (YARPP) » YERPP displays default img instead of featured image

  • Resolved fert


    I’ve been using YARPP for at least 2 years now and have not touched it since I set it up. If I remember corretly there have been some major updates in between.

    My problem is: YARPP displays the default image (as set in the template) on many posts although it should use the featured image (there is one in in every post I write). It seems as though it only picks the first image from each post.

    Since this is a running installation, I don’t want to break anything. I did some major CSS reconfiguration “back then” but have no idea at all what it was and how I could get it back up after fiddling with it now. It appears the “settings” interface has changed dramatically and right now I don’t eben know what the templates are used for.

Viewing 6 replies - 1 through 6 (of 6 total)
  • In the new YARPP settings page, are you using “thumbnails” or “custom (PHP)” in the “Display options for your website” section? The “thumbnails” display is the new feature (released a few months ago) which will display your featured image.

    Were you using YARPP to display images for your related posts in the past? If that’s the case, you probably want to continue to use the “custom” option.

    I’ve been using a custom template before and displayed images for the related posts, yes. And the current setting already is to “custom” and the template is specified.

    Here’s the template’s code:

    <?php if ($related_query->have_posts()):?>
    <h3 class="meta">&Auml;hnliche Beitr&auml;ge</h3>
    	<ul class="related-posts">
    		<?php while ($related_query->have_posts()) : $related_query->the_post(); ?>
    				//Set character cap, default is 30
    				$related_thumbnail = get_post_meta($post->ID, "thumbnail_url", $single = true);
    				$imgthumb = catch_that_image();
    				$tit = the_title('','',false);
    				$tit1 = substr($tit, 0, 38);
    				if (strlen($tit) > 38) { $tit2 = "$tit1 ..."; } else { $tit2 = "$tit"; }
    				<a href="<?php the_permalink() ?>" rel="bookmark">
                		<?php if ($related_thumbnail != "") : ?>
                			<img src="<?php echo $related_thumbnail; ?>" alt="<?php the_title(); ?>" height="100" />
               	   		<?php else : ?>
    					<?php if ($imgthumb != "") : ?>
    						<img src="<?php echo $imgthumb; ?>" alt="<?php the_title(); ?>" height="100" />
    					<?php else : ?>
    						<img src="/wp-content/uploads/ug_default_thumbnail.png" alt="<?php the_title(); ?>" height="100" />
    					<?php endif; ?>
                	    <?php endif; ?>
    					<div class="related-posts-text"><?php echo $tit2; ?></div></a>
    		<?php endwhile; ?>
    <?php else: ?>
    <?php endif; ?>

    Since this works for all posts with their own image but not for those who only have a featured image, I presume this code actually looks for the first image in any post. If that is the case, how could I change that to use the featured image? I’ve done quite some CSS work for this template and I’m not sure if I would be able to quickly implement the “new” thumbnails option (does it display the post title alongside the image?).

    Hmm… you’re using this function catch_that_image() in there in the crucial part (to find the image) but I don’t recognize that, so I can’t help you. Maybe you have some other plugin which supplies that function? Maybe that other plugin is now misbehaving?

    I agree with you that fixing the template you have now may be simpler than trying to switch to the new “thumbnails” feature in YARPP… doing so would probably require significant rewriting of your custom CSS.

    Thanks a lot for looking into this. Now I remember: There was a point up until which I did not have a featured image in every post (I think that option did not exist in Wordpess 2.?). But every post had an image.

    So there was not always a featured image, but an image in the post and I found this code somewhere:

    function catch_that_image() {
      global $post, $posts;
      $first_img = '';
      $output = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
      $first_img = $matches [1] [0];
      if(empty($first_img)){ //Defines a default image
        $first_img = "";
      return $first_img;

    Which I put into my functions.php – and it obviously does its job. But now I need to find a way to make it look for a featured image first, right?

    I think of something like

    if there is a featured image
      -> use featured image
     ->look for first image in post or use default image

    Question is (me always trying to become better at this but forgetting how to code everytime) is that more work than rewriting the CSS for your plugin option?

    My Theme is Atahualpa, by the way, if that makes any difference.

    OK, I thought it would be neat to remove that custom function so I decided to go with your option and re-style that. ’twas some work but I needed much less CSS.

    Thanks again!

    Great! Glad you got it working.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘YERPP displays default img instead of featured image’ is closed to new replies.