Hey I just wanted to know how to add an element after the first thumbnail image in my loop. Basically I want an HTML div tag inserted after the first image in my post. Anyone know how to do that in WordPress, heres what I have:

<?php if(has_post_thumbnail()){
                  $post_pic  = get_the_post_thumbnail();
                  $post_pic .= '<div></div>';
                  return $post_pic;
?>

1 Answer
1

If you just want to target the first item you can define a variable $first_round=true before you start the loop. Inside the loop, towards the end, you do $first_round=false. So this variable is only true the first time you go through the loop and you can add

if ($first_round) echo '<div>...</div>'

right after your call to the_post_thumbnail().

Leave a Reply

Your email address will not be published. Required fields are marked *