Web Resources - JungleJar
JungleJar / tutorials / wordpress / Insert Your Ads Dynamica…

Insert your ads dynamically into your Wordpress posts.

  • Published by: christopher
  • 24-05
This will insert an “ad-system” such as Adwords, link-ads, basically anything, even if it isn’t ad-related after X number of posts have been displayed. It just so happens that this method works great for displaying ads.

I typically like to keep my ad content in its own .php file as it keeps file-sizes low and keeps things categorized.

Do these in order:

Create an ASCII text file named adsys.php in your template directory.
In this file you would place your adsense code or whatever CSS element you’d like.
I would create a tight CSS division to style/place my Adsense ads like I wanted.
A div such as

.wrapped {
width:auto;
height:auto;
padding:20px
}

would work just fine.

Now we just carefully set up our Wordpress loop(s) so that they call everything correctly.

<?php while (have_posts()) : the_post(); $loopcounter++; ?>
<?php if ($loopcounter == 3) { include (TEMPLATEPATH . ‘/adsys.php’); } ?>
<?php the_content(); ?>
<?php endwhile; ?>

Yoku deki mashta.

This would insert our Adsense code from adsys.php into our index.php or whatever page/category/etc we were posting to after 2 posts. On post 3, it would call adsys.php and then loop like normal.

Leave a Reply

You must be logged in to post a comment.

© JungleJar.com / aukyo.com | Designed by: introportfolio.com