Recently, I added Google AdSense to my site. I wanted to have an ad beneath the last post on each page, and another ad in the middle of pages with multiple posts. To do this I needed to figure out the total number of posts in the current loop. I had a hard time figuring out how to do this so I wanted to share what I learned.
The $post_count and $current_post properties of the WP_Query class provide the total number of posts in the query and the index of the current post respectively. By using these two values I was able to identify the middle post and the last post on every page.
