[Resolved] Infinite scroll ads once every X posts

Home Forums Support Infinite scroll ads once every X posts

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #295681
    Adrian Cojocariu

    Hey man, I’ve mixed Infinite Scroll plugin and masonry to generate posts as they scroll.

    Then I use Ad inserter plugin to put ads between posts. The thing is it only generates the ads for the first page and not the others that ajax calls in.

    This is what the ad inserter plugin author says.

    “It seems that ajax calls (for infinite scroll) do not call post hook which is needed for insertion between posts.
    It is called only 8 times for the inital page load.
    Please try to contact theme author.”

    You can read full thread here.

    https://wordpress.org/support/topic/infinite-scroll-68/#post-8940687

    Can you give me a hint on what to look in ? How can I call the post hook for every new page generated with Ajax.

    #295832
    Tom
    Lead Developer
    Lead Developer

    I’m not sure what he means by “post hook”. Maybe he can explain a bit more?

    Basically, the load more button has the URL to the next page attached to it, on click we use jQuery.GET to pull the content from the next page and display it on the current page. It should be the same content as when you go to yoursite.com/page/2

    #296154
    Adrian Cojocariu

    Ok I asked him and he said this:


    the_post hook is used to insert code between posts:
    https://codex.wordpress.org/Plugin_API/Action_Reference/the_post

    I’m not sure where the template for the blog page is, is it index.php in the Theme folder ? Or archives.php ?

    I checked both of them and the_post seems to be there:

    
    <?php while ( have_posts() ) : the_post(); ?>
    
    #296376
    Tom
    Lead Developer
    Lead Developer

    The theme definitely uses the_post() – the blog posts wouldn’t work without it.

    I’m not sure ow the plugin inserts ads, but the theme pulls in the second page of posts using the URL (yoursite.com/page/2). If the ads are inserted on load, then I guess this wouldn’t work as that page never truly loads, jQuery loads it for you.

    #296672
    Adrian Cojocariu

    Tom, I tested with pages. Definitely, it works when the blog is paginated. If I click on page 2,3,4 the ads show up between the posts.

    So it’s the Ajax call that gives me problems… when I use masonry and click load more button to generate new posts… the ads don’t show up.

    Any ideas ?

    From what I understand, if the ads are inserted on load, you mean like page load when you press F5 on Windows. Then jQuery pulls the new pages, but the insert ads code isn’t loaded again so ads only show then.

    #296818
    Tom
    Lead Developer
    Lead Developer

    It depends on how the plugin is inserting the ads. It seems whatever method the developer is using to do that isn’t compatible with plugins that load the posts using AJAX. This would probably be the case no matter which infinite scroll plugin you used.

    One solution would be to use jQuery to insert your ads as you loaded more posts, but that would be pretty complicated.

    #297010
    Adrian Cojocariu

    Yeah, I’m also thinking it’s the plugin’s fault, although there is a patch where it said it now supports Ajax (for endless scroll) but it doesn’t seem to work. I do have an Ajax check button in settings though. Maybe conflict with some other plugin, but I don’t have many, and it doesn’t work with twentysixteen either so it’s not theme conflict…

    #297012
    Adrian Cojocariu

    This is what he said.

    Ad Inserter uses the_post hook to insert ads between posts.
    Each time the_post hook is called Ad Inserter writes code block for this position (according to settings). In normal cases the code then appears between posts.

    Ad Inserter also checks page type.
    WP Page types

    Ad Inserter Misc settings

    In your case it is Homepage (PHP check: is_front_page () )
    PHP check for the ajax call: defined (‘DOING_AJAX’) && DOING_AJAX)

    However, if javascript loads yoursite.com/page/2 then Ad Inserter does not see this as standard WP ajax call but ordinary homepage. If you debug processing for yoursite.com/page/2 you’ll see:

    MULTISITE: NO
    USER: NOT LOGGED-IN
    PAGE TYPE: HOMEPAGE
    ID: 1539
    URL: /chwgdev/page/2/
    Since Ad Inserter works normally when you load page yoursite.com/page/2 in the browser I assume Ad Inserter works as expected.

    I have debugged the code and ajax calls and I can see the Javascript loads yoursite.com/page/2 and next pages with Ad Inserter codes inserted as configured and expected.

    Therefore, you need to check with the theme author why the page is not displayed as it is loaded.

    You can simply compare the page (html code) that is returned with the ajax call (with inserted code blocks) and the page (html code) that is displayed when you scroll (no inserted code blocks).

    #297242
    Tom
    Lead Developer
    Lead Developer
    #298989
    Adrian Cojocariu

    Nah man, tiz don’t work. Not at all actually, no ads at all, must be doing smth wrong but I got bored trying tbh.

    🙁

    It’s not the theme my opinion. All plugin use sam ajax file right ?

    It might be that the plugin for inserting ads isn’t well set up, but who knows.

    This is what he said last time.

    Ad Inserter uses the_post hook to insert ads between posts.
    Each time the_post hook is called Ad Inserter writes code block for this position (according to settings). In normal cases the code then appears between posts.

    Ad Inserter also checks page type.
    WP Page types

    Ad Inserter Misc settings

    In your case it is Homepage (PHP check: is_front_page () )
    PHP check for the ajax call: defined (‘DOING_AJAX’) && DOING_AJAX)

    However, if javascript loads yoursite.com/page/2 then Ad Inserter does not see this as standard WP ajax call but ordinary homepage. If you debug processing for yoursite.com/page/2 you’ll see:

    MULTISITE: NO
    USER: NOT LOGGED-IN
    PAGE TYPE: HOMEPAGE
    ID: 1539
    URL: /chwgdev/page/2/
    Since Ad Inserter works normally when you load page yoursite.com/page/2 in the browser I assume Ad Inserter works as expected.

    I have debugged the code and ajax calls and I can see the Javascript loads yoursite.com/page/2 and next pages with Ad Inserter codes inserted as configured and expected.

    Therefore, you need to check with the theme author why the page is not displayed as it is loaded.

    You can simply compare the page (html code) that is returned with the ajax call (with inserted code blocks) and the page (html code) that is displayed when you scroll (no inserted code blocks).

    #299031
    Tom
    Lead Developer
    Lead Developer

    The fact is doesn’t work with that plugin either tells me that the plugin simply isn’t compatible with AJAX calls for most posts unfortunately.

    It might be something the developer needs to look into added if they’re interested.

    Not sure it’s something the AJAX script can account for unfortunately.

    #299280
    Adrian Cojocariu

    Yeah… well he doesn’t seem to be able to fix it, maybe it’s some other plugin conflicting or I’m doing smth wrong. I’ll try it later on on a new install see if it works there and also with some other themes. Thanks man !

    #299481
    Tom
    Lead Developer
    Lead Developer

    Might be worth telling him to test his plugin with that other AJAX plugin. Theme shouldn’t matter.

    If he gets it working with that plugin, it should work with the GP masonry load more as well.

    #303058
    Adrian Cojocariu

    Man, I just tested more on GP.

    I tried adding my code in the archive.php template and it still doesn’t get pulled in the masonry loaded pages.

    This is through default stuff that comes with GP.

    Any ideas ?

    #303239
    Tom
    Lead Developer
    Lead Developer

    Not too sure what you mean? I’m 99% sure it’s the way the plugin is adding the ads which isn’t compatible with AJAX loading (whether it’s GP or another infinite scroll/ajax load more plugin).

Viewing 15 posts - 1 through 15 (of 19 total)
  • You must be logged in to reply to this topic.