- This topic has 7 replies, 2 voices, and was last updated 6 months, 2 weeks ago by Leo.
January 30, 2020 at 1:19 pm #1149778marv3x
Hello, I’m trying to add some adsense between posts in the archives and homepage.
I was trying to use the Ad Inserter plugin, but it doesn’t show right the count of posts.
Can it be done by hooks?
Thanks a lot.January 30, 2020 at 4:09 pm #1149854LeoStaffCustomer SupportJanuary 30, 2020 at 9:54 pm #1149961marv3x
Unfortunately, Ad Inserter doesn’t work on the theme, in that functionality. Do you know any alternative?
Thanks!January 30, 2020 at 10:13 pm #1149965LeoStaffCustomer Support
Sorry we are talking about this plugin right?
It should work with GP – can you explain the issue a bit more?
And the same issue doesn’t exist if you activate a default twenty series theme?
Let me know 🙂January 30, 2020 at 10:33 pm #1149974marv3x
You can look here:
It does not display the posts correctly. And every category have different orders.January 31, 2020 at 9:25 am #1150610LeoStaffCustomer SupportJanuary 17, 2021 at 6:38 am #1622233Ian
I apologize if this is not the right place to share this since this is an older topic, but I happened to come across it and I hadn’t seen the information elsewhere in the support forums.
I just wanted to share a solution I found for this that worked for me in case anybody else is facing a similar scenario.
I was looking for a way to insert ad code after a certain number of posts (i.e. every nth post) on the archives and home pages without a child theme or plugin.
I created a new hook element set to display on the front page and all archives pages, allowed PHP to execute and attached it to the
generate_before_contenthook. Then I added this code:
<?php global $loop_counter; $loop_counter++; // show ad every 4th post if ( $loop_counter % 4 == 0 ): ?> <!-- ad code here --> <div style="width:728px;height:90px;border:1px solid #000;"> Sample ad space </div> <?php endif; ?>
Instead of every 4 posts, you could obviously change it to suit your needs, i.e. every 5 posts, 2 posts, etc.
You could also do something like this to show an ad between specific posts (#2 and #7 in this example):
<?php global $loop_counter; $loop_counter++; if ( $loop_counter == 2 or $loop_counter == 7 ): ?> <!-- ad code here --> <div style="width:728px;height:90px;border:1px solid #000;"> Sample ad space </div> <?php endif; ?>
I hope this is potentially helpful to others!January 17, 2021 at 10:24 am #1622644
- You must be logged in to reply to this topic.