Search code examples
phphtmlwordpressloopsposts

Add a div after the first post in Wordpress loop


I am currently working on blog page for a custom Wordpress theme. This page consists of all the posts available in thumbnail format. You click a thumbnail, you go to that post. I know how to do a basic post loop so every thumbnail shows. I also know how to add HTML within that loop. However I need to know how to add a div ONLY after the first post is placed. The first post that's placed should be the latest post, thus the largest. Next to that I need another div that has nothing to do with the posts.

How do I make a loop that places a div ONLY after the first post. Then continues placing the other post thumbnails. See the image below.

enter image description here


Solution

  • you can use a basic if constuct. Before a loop starts set variable

    $someVariable = 0;
    

    then in the loop, after the post is displayed:

    if ($someVariable == 0) {
     print "<div>whatever</div>"
     $someVariable++;
    }