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.

How can I can I check if a post has a thumbnail and if does do something? If doesn't do something else. This is what I have:

 <?php if (has_post_thumbnail()) ?>

 <?php the_thumbnail(); ?>
 ?>

 <?php else ?>

 <?php the_permalink();?>

 <?php endif; ?>

Any help will be appreciate it.

share|improve this question
add comment

1 Answer

You need to use the_post_thumbnail instead of the_thumbnail within the loop. This is how it should be formatted:

<?php if(have_posts()){
    while(have_posts()){
        the_post();
        if(has_post_thumbnail()){
            the_post_thumbnail();
        }
    }
}?>
share|improve this answer
    
Sorry I'm kind of new to WP, would this go inside the <?php if (have_posts()) : ?> loop??? –  jorame Feb 16 '12 at 3:31
    
You are correct! The loop populates these functions with the current postdata. :) –  Brian Fegter Feb 16 '12 at 3:33
    
Would this give me any results '<?php if (have_posts()) : ?> <?php while (have_posts()) : the_post()?> <?php if (has_post_thumbnail()) { the_post_thumbnail(); } ?> <?php endwhile; ?> <?php endif; ?>' –  jorame Feb 16 '12 at 3:35
    
Instead of using all the <?php tags see my edited example. –  Brian Fegter Feb 16 '12 at 3:36
add comment

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.