Apply filters/modifications to posts loaded via AJAX

Hello all,

I've been working on a child theme which includes a masonry-type layout. To achieve this I created a masonry.php file which contains all the actions/filters/modifications to the base post look (adding the necessary javascript, moving the image above the title, displaing the excerpt instead of the full post text, etc.). This file is then linked in the index.php file with a simple include_once('masonry.php');.

This (with some CSS and other minor tweaks) has resulted in this look (you can ignore the posts themselves, they're all just placeholders to test various theme features).

What I'm actually having trouble with is trying to add endless scrolling to the landing page. I figured I'd use the Jetpack feature to accomplish this (as outlined here). This is the code I have right now (in my functions.php file):

// add infinite scroll functionality
function helios_infinite_scroll_init() {
  add_theme_support( 'infinite-scroll', array(
    'type'      => 'click',
    'container' => 'masonry',
    'wrapper'   => true,
    'render'    => 'beans_loop_template', //FIXME: render function needs to go through code in masonry.php (?)
  ) );
add_action( 'after_setup_theme', 'helios_infinite_scroll_init' );

This works exactly as intended (the next page of posts is displayed on the page) with one important caveat: none of the modifications from the masonry.php file are applied to these posts. I get the full post text, none of my custom CSS classes, the image is still under the title, etc. (Here's a screenshot of a post loaded with Jetpack, if that helps understand what I'm saying).

My best guess is that the render function is wrong, but I haven't really been able to figure out exactly what to put there to make it work. Anyway, all this to say that I was wondering if anyone on here might have some insight on how to fix this problem.

Edited 3 weeks, 6 days ago by Thomas Lynch

Sorry no one's replied in 1.5 weeks...

Have you got a public repository for this child theme you're building? It would be easier to address this seeing what you've got in masonry.php.

Write a reply

Login or register to write a reply, it's free!