Hey,
What i want to do i quite simple : when inside The Loop, i want to retrieve the current post count.
For example, after every 3 posts, i want to insert an ad.
So, how do i get the value of the loop count?
Cheers,
Kartik Rao
Hey,
What i want to do i quite simple : when inside The Loop, i want to retrieve the current post count.
For example, after every 3 posts, i want to insert an ad.
So, how do i get the value of the loop count?
Cheers,
Kartik Rao
You can use the current_post
member of the WP_Query
object instance to get the current post iteration;
while (have_posts()): the_post();
if ($wp_query->current_post % 3):
// your ad code here
endif;
// your normal post code
endwhile;
Note, if you're using this inside a function, you'll need to globalise $wp_query
.
Why not incrementing a variable then display your ads when needed?
while(LOOP)
echo $i%3==0 ? $ad : '';
$i++