• Resolved mayurjango

    (@mayurjango)


    Hi, I’m displaying 12 posts on homepage without any excerpt and I want to ad an adsense unit in the middle of them, i.e. ad ad unit right after 6 posts. The ad unit should also appear after 6 post on next page(/page/2) and so on. Similarly, the ad should appear after 6 posts when viewing on a smartphone.

    How can I do it?

    Site: https://webtrickz.com

Viewing 3 replies - 16 through 18 (of 18 total)
  • Yes, that’s possible. However, since you’ve already marked this topic as resolved, how about starting another one with your two questions (or one combined question) above. Regarding the css, that’s because your test site had a <div align=”center”> right after the text widget where your original site does not. Try this css on the original site:

    #text-16.widget {
      padding-bottom: 15px;
      clear: both;
      text-align: center;
      }

    mayurjango – ok, never mind with the new post. I thought it was going to be more involved. So, first case, if you want to show the ad after 6 posts, but not after 12, change this line:

    if ($i % 4 == 0) {   // if we've shown 4 posts

    to this:

    if (($i % 6 == 0) && ($i <> 12)) {   // if we've shown first 6 posts

    If you want to show the ad after 4 posts and 8 posts, but not after 12, change this line:

    if ($i % 4 == 0) {   // if we've shown 4 posts

    to this:

    if (($i % 4 == 0) && ($i <> 12)) {   // if we've shown 4 or 8  posts

    Using that pattern you could display them pretty much as often as you want. Hope that helps.

    Thread Starter mayurjango

    (@mayurjango)

    Woah.. Simply works as I wanted. You’re so amazing bdbrown. ??

    Thanks for providing the solution within this post itself. Would be easier for others to locate as well.

Viewing 3 replies - 16 through 18 (of 18 total)
  • The topic ‘Add Adsense ad in middle of posts on index page’ is closed to new replies.