[Support request] How to display ads between posts

Home Forums Support [Support request] How to display ads between posts

Home Forums Support How to display ads between posts

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1149778
    marv3x

    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.

    #1149854
    Leo
    Staff
    Customer Support

    Hi there,

    Unfortunately there are no hooks between the posts blocks.

    A plugin like Ad Inserter is required.

    Hope this helps!

    #1149961
    marv3x

    Oh ๐Ÿ™
    Unfortunately, Ad Inserter doesn’t work on the theme, in that functionality. Do you know any alternative?
    Thanks!

    #1149965
    Leo
    Staff
    Customer Support

    Sorry we are talking about this plugin right?
    https://en-ca.wordpress.org/plugins/ad-inserter/

    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 ๐Ÿ™‚

    #1149974
    marv3x

    You can look here:

    It does not display the posts correctly. And every category have different orders.

    #1150610
    Leo
    Staff
    Customer Support

    How are you implementing it? Just by activating the plugin?

    Does it work out of the box when using a twenty series WP theme?

    #1622233
    Ian

    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_content hook. 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!

    #1622644
    Leo
    Staff
    Customer Support
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.