$count++;
if $count==4 {insert ad; $count=0}
drop it in the loop right after the post.
I'm pretty sure there is an adsense plugin that can handle that. However, I refuse to search for it for you!
if(have_posts() : ...
<?php $postnum = 1; ?>
<div class="entry"> ... </entry>
<?php if(($postnum % 4) == 0) : ?>
<!--adsense code here-->
<?php endif;
$postnum++; ?>
in index.php:
1
before the line
add:Code:if(have_posts() : ...
2Code:<?php $postnum = 1; ?>
after the block
add:Code:<div class="entry"> ... </entry>
Oh yeah.Code:<?php if(($postnum % 4) == 0) : ?> <!--adsense code here--> <?php endif; $postnum++; ?>
Thanks for the code, i implemented it in index.php, but now its showing after post 1 and after post 4. How do i do it so that it shows after post 4?
<?php get_header(); ?>
<div id="column">
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<!-- ^^^^^^^^^^^^^^ post code ^^^^^^^^^^^^^^ -->
<div class="post" id="post-<?php the_ID(); ?>">
<div class="post-top"></div>
<div class="entry">
<h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<span class="date"><?php the_time('l, F j, Y'); ?> <?php the_time('G:i'); ?></span>
<div class="info">
<div class="cat">Posted in category <?php the_category(', ') ?></div>
<div class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></div>
<div class="clear"></div>
</div>
<div class="content">
<?php the_content('Read the rest of this entry »'); ?><div class="clear"></div>
</div>
<div class="tags"><?php edit_post_link('Edit', '', ' | '); ?><?php the_tags('Tags: ', ', ', ''); ?></div>
</div>
<div class="post-bottom"></div>
</div>
<!--adsense code here-->
<?php if(($postnum % 4) == 0) : ?>
<?php endif;
$postnum++; ?>
<!--adsense code here-->
<!-- ^^^^^^^^^^^^^^ post code ^^^^^^^^^^^^^^ -->
<?php endwhile; ?>
<!-- ^^^^^^^^^^^^^^ post navigation ^^^^^^^^^^^^^^ -->
<div class="navigation">
<!-- Start Of Script Generated By WP-PageNavi 2.20 -->
<center><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?></center>
<!-- End Of Script Generated By WP-PageNavi 2.20 -->
</div>
<!-- ^^^^^^^^^^^^^^ post navigation ^^^^^^^^^^^^^^ -->
<?php else : ?>
<!-- ^^^^^^^^^^^^^^ page not found + search form ^^^^^^^^^^^^^^ -->
<div class="post">
<div class="post-top"></div>
<div class="entry">
<div class="content">
<h1>Page Not Found</h1>
<p>Sorry, but you are looking for something that isn't here.</p>
<h3>Search Blog</h3>
<?php include(TEMPLATEPATH."/searchform.php"); ?>
</div>
</div>
<div class="post-bottom"></div>
</div>
<!-- ^^^^^^^^^^^^^^ page not found + search form ^^^^^^^^^^^^^^ -->
<?php endif; ?>
</div>
<?php get_sidebar(); ?>
<?php get_footer(); ?>
Code:<?php get_header(); ?> <div id="column"> <!-- ################# ADD ############### --> <?php $postnum = 1; ?> <!-- ======================================== --> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> <!-- ^^^^^^^^^^^^^^ post code ^^^^^^^^^^^^^^ --> <div class="post" id="post-<?php the_ID(); ?>"> <div class="post-top"></div> <div class="entry"> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <span class="date"><?php the_time('l, F j, Y'); ?> <?php the_time('G:i'); ?></span> <div class="info"> <div class="cat">Posted in category <?php the_category(', ') ?></div> <div class="comments"><?php comments_popup_link('No Comments', '1 Comment', '% Comments'); ?></div> <div class="clear"></div> </div> <div class="content"> <?php the_content('Read the rest of this entry »'); ?><div class="clear"></div> </div> <div class="tags"><?php edit_post_link('Edit', '', ' | '); ?><?php the_tags('Tags: ', ', ', ''); ?></div> </div> <div class="post-bottom"></div> </div> <!-- ############# REMOVE: ################### --> <!--adsense code here--> <!-- ============================================ --> <?php if(($postnum % 4) == 0) : ?> <!-- ############### ADD: #################### --> <!-- adsense code here --> <!-- ============================================== --> <?php endif; $postnum++; ?> <!-- ############## REMOVE: ################## --> <!--adsense code here--> <!-- ================================================ --> <!-- ^^^^^^^^^^^^^^ post code ^^^^^^^^^^^^^^ --> <?php endwhile; ?> <!-- ^^^^^^^^^^^^^^ post navigation ^^^^^^^^^^^^^^ --> <div class="navigation"> <!-- Start Of Script Generated By WP-PageNavi 2.20 --> <center><?php if(function_exists('wp_pagenavi')) { wp_pagenavi(); } ?></center> <!-- End Of Script Generated By WP-PageNavi 2.20 --> </div> <!-- ^^^^^^^^^^^^^^ post navigation ^^^^^^^^^^^^^^ --> <?php else : ?> <!-- ^^^^^^^^^^^^^^ page not found + search form ^^^^^^^^^^^^^^ --> <div class="post"> <div class="post-top"></div> <div class="entry"> <div class="content"> <h1>Page Not Found</h1> <p>Sorry, but you are looking for something that isn't here.</p> <h3>Search Blog</h3> <?php include(TEMPLATEPATH."/searchform.php"); ?> </div> </div> <div class="post-bottom"></div> </div> <!-- ^^^^^^^^^^^^^^ page not found + search form ^^^^^^^^^^^^^^ --> <?php endif; ?> </div> <?php get_sidebar(); ?> <?php get_footer(); ?>