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?
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?
You must be logged in to post a comment.
You can use the
current_post
member of theWP_Query
object instance to get the current post iteration;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?
Unsure why, but the suggested methods didn’t work out for me, I had to resort to the following
Safer than playing with globals if you ask me.