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
1 2 3 4 5 | .wrapped { width:auto; height:auto; padding:5px } |
would work just fine.
Now we just carefully set up our Wordpress loop(s) so that they call everything correctly.
1 2 3 4 | <?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.
September 6th, 2008 at 6:40 am
im sory please remove my 2comment before
i tried many time on this but the result was error, can you explain how to do this more detail??
i want to place ads after 2 post in index.php,
so where i should put those loop code??
i tried in everywhere but always error
thx
September 8th, 2008 at 4:46 pm
The code needs to be inserted in the Wordpress Loop. E-mail me your troubles, and I’ll show you what you’re doing wrong.