How to put a div inside the php loop?
-
I would like to make a div conditional on whether there is an image or not. If there is a featured image, I want the div (containing the image) to appear. If there is no image, I don’t want the div.
I have been working on this code:
<div class="div-1"> <?php $posts = get_posts( "cat=50&numberposts=1" ); ?> <?php if( $posts ) : ?> <?php foreach( $posts as $post ) : setup_postdata( $post ); ?> <a href="<?php echo get_permalink($post->ID); ?>" > <?php if ( has_post_thumbnail()) : the_post_thumbnail('titleof-thumb'); endif; ?> </a> <?php endforeach; ?> <?php endif; ?> </div>
I’ll spare you the things I tried to add after the if statement “if (has_post_thumbnail()) : ” but I get errors when I try to put a div in there. I want to say “if has thumbnail, then show div with thumbnail” instead of (already have) “if has thumbnail, show thumbnail.
Thanks for any help
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How to put a div inside the php loop?’ is closed to new replies.