0

I'm a web developer who's new to WordPress. I've been asked to write a custom theme for one of my clients, in other words starting from the ground up. I used Underscores as a foundation and have been writing mostly custom styles on top of that.

They've asked if it would be possible to implement infinite scroll on the category landing pages. I've been looking at a few plugins like Ajax Load More to hopefully not have to write this functionality this by hand.

What I'm wondering is -- do plugins such as Ajax Load More work properly in the context of a custom theme? Based on what I know about plugins, my guess is that this is operates using filters, but I'm not sure what it hooks into, or how to know if I'm providing that hook in the theme.

I know this is a bit of a hazy question, but I'm mainly trying to understand what determines compatibility between a particular plugin and a theme. Do all WordPress themes inherently have the same hooks? How can I know what hooks the plugin expects? Any insights or clarifying thoughts would be much appreciated.

  • 2
    Any theme can leverage WP Hooks. However, this plugin doesn't rely on a hook. It creates code for you to add to your template/theme files. Plugins don't necessarily use hooks/filters. – disinfor Mar 23 at 20:35
  • There's no single answer to your question. All plugins work differently. To know if your custom theme requires something specific to work with a plugin, you will need to consult that plugin's documentation. – Jacob Peattie Mar 24 at 15:28
1

Underscores.me Framework has integrated support for Jetpack's Infinite Scroll feature - you could just install the Automattic JetPack plugin and ensure that the Infinite Scroll feature is enabled.

Lines 155-156 of the default underscores.me framework add Jetpack support if it's installed:

/**
 * Load Jetpack compatibility file.
 */
if ( defined( 'JETPACK__VERSION' ) ) {
    require get_template_directory() . '/inc/jetpack.php';
}

In that Jetpack include file (/inc/jetpack.php) on lines 17-23 you get:

function test_jetpack_setup() {
// Add theme support for Infinite Scroll.
add_theme_support( 'infinite-scroll', array(
    'container' => 'main',
    'render'    => 'test_infinite_scroll_render',
    'footer'    => 'page',
) );

I've never used an infinite scroll for standard WordPress posts/content but I have written my own for custom post types like a portfolio - I've looked at the code and it's really use-case specific and I don't know if it'd be much help to you.

Basically I write out an new WP_Query (outside of the loop) to load 12 of the the custom post-type's posts, then I write a javascript that triggers an AJAX function to load more posts and append them to the parent container when the user scrolls to an existing point in the page and then write a callback that executes a new WP_Query for the AJAX call to use as an action.

Hope this all helps.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.