Categories: Tips & Tricks

Adding a external file after the first post

How might you display a Google ad after the first post or anything you like? It is very simple. You just need to add the variable $loopcounter in the Loop. If the $loopcounter is less than or equal to 1, then include your option. Check out the code:

<?php if (have_posts()) : while (have_posts()) : the_post(); $loopcounter++; ?>

  // your loop

  <?php if ($loopcounter <= 1) { include (STYLESHEETPATH . '/you-file.php'); } ?>

<?php endwhile; ?>

<?php else : ?>

<?php endif; ?>

Pretty simple huh. Well in the $loopcounter line, you may change the include to point to any file or maybe a custom widget like so:

<?php if ($loopcounter <= 1) { dynamic_sidebar( 'Plus Post' ); } ?>

Or use your code directly in between the { & }.

Web Master

Hi, I am Miguel, I bought this site in 2009. So I now run or manage the site. Please visit my new website or follow me on twitter @W3i.

View Comments

Recent Posts

The state of the Press

I might like to start off by saying Happy Birthday WordPress. I don't have any…

1 hour ago

Podcasting with Dave Moyer

Planning Who let you in? Format Daily Weekly Monthly Hour/half hour A show's Outline -…

11 hours ago

Cooking with BuddyPress

I'm sitting downstairs at WordCamp 2009 in San Fransisco. Up on stage right now, Andy…

23 hours ago

18 Photo Editing apps to try in 2024.

Choosing the best photo editing apps for e-commerce depends on your specific needs and budget.…

1 day ago

The WordPress Logo

For your information. The WordPress fonts are as follows: the old WP logo was Dante,…

2 days ago

WordPress 2.8 beta 2 now available

WordPress announced the release of 2.8 beta 2, download it or check out the changes since…

2 days ago