Adding Content Between Posts – WordPress Loop

Here’s a simple trick I’ve been using to include an ad after the second post, however you could modify the location.

<?php if ( $count == 1 ) : ?>
  <div class="special">
   Content Here
  </div>
<?php endif // ( $count == 2 ) ?>

<?php $count++ ?>
<?php endwhile; ?>

Notice the code is added just before the

<?php endwhile; ?>

in your loop.

About the Author, Dan Cameron:

I'm the owner and solution engineer at Sprout Venture, a web solutions company that specializes in web development including WordPress.

I started my first blog in 2003 and transitioned to WordPress in 2004. Since moving to WordPress I've written a few plugins and themes for public consumption. Lately I'm busy engineering/building/coding and have only been able to share a few code snippets.

If you're in need of some web development, web design or custom WordPress plugins and/or themes contact me, I'll be happy to discuss it with you.

Read More »

  • Claudio
    It worked well at index.php but not in page.php. Why?
  • page.php isn't a loop. It's a content page.
  • Claudio
    Dan what is the solution for this type of pages?
  • If you want to insert info after the content, open up the page.php file and add it after <?php the_content ?>
  • Claudio
    Dan I understood for the case of page.php.
    My WP is set to display 8 posts in each page. I want to put info after the first post of each page.
    Post 1 - Info1 | Post 9 - Info 1 | Post 17 - Info 1

    1 + 1*8

    for( var i:int = 0; i<Total number of posts; i++ )

    This is my idea.

    Thanks
blog comments powered by Disqus