Support » Fixing WordPress » Default Thumb Problem

  • Im trying to use a default thumb if no post image exists but something is wrong and I keep getting a blank default. Help please.

    <?php $thumb = catch_that_image(); ?>
          <?php if ( $thumb ) { ?>
               <img src="<?php echo $thumb; ?>" width="50" height="50" />
           <?php } else { ?>
                <img src="http://mysite.com/wp-content/themes/fod/images/image.png" width="50" height="50" />
           <?php } ?>
Viewing 5 replies - 1 through 5 (of 5 total)
  • Do you have a link to a page where this is occurring?
    Your code looks fine as long as catch_that_image() actually is returning a URL. I’ve never seen that function before by the way. Why aren’t you using get_the_post_thumbnail()?

    Thread Starter enderpal444

    (@enderpal444)

    The site is behind an under construction so I can’t. The function grabs the first image of the post and uses it for the thumb and that works fine. My problem is getting the default thumb I provided to show if the $thumb doesn’t exist. The link for it is correct but when I view the page source it shows a link for to “images/default.jpg”. Im super confused.

    Just as a debug routine, try giving the image in your else block a width and height of 75 and then reloading the page. This way you’ll be able to fully tell the difference between whether or not the if statement is succeeding. In other words, change your code to this:

    <?php $thumb = catch_that_image(); ?>
          <?php if ( $thumb ) { ?>
               <img src="<?php echo $thumb; ?>" width="50" height="50" />
           <?php } else { ?>
                <img src="http://mysite.com/wp-content/themes/fod/images/image.png" width="75" height="75" />
           <?php } ?>

    Reload the page and look at the source. Is the image with width/height of 75 the one showing or is it still the 50×50?

    If it’s the 50×50, then catch_that_image is actually returning the images/default.jpg and so your else statement is never being ran.

    Thread Starter enderpal444

    (@enderpal444)

    lol yeap thats exactly what it was. Thanks for being way smarter than me Jacob!

    Hehe, just glad I could help 🙂

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Default Thumb Problem’ is closed to new replies.