WordPress.org

Ready to get started?Download WordPress

Forums

Default Thumb Problem (6 posts)

  1. enderpal444
    Member
    Posted 2 years ago #

    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 } ?>
  2. Jacob Chappell
    Member
    Posted 2 years ago #

    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()?

  3. enderpal444
    Member
    Posted 2 years ago #

    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.

  4. Jacob Chappell
    Member
    Posted 2 years ago #

    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 50x50?

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

  5. enderpal444
    Member
    Posted 2 years ago #

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

  6. Jacob Chappell
    Member
    Posted 2 years ago #

    Hehe, just glad I could help :)

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.