Jetpack infinite scroll & X Theme

I may be having trouble because I don’t know the correct <div> ID to name as the target in the X Ethos theme. I know you don’t provide Jetpack support, but please tell me as much as you can as it relates to the X theme’s conventions.

I tried to get it working in Ethos and failed, but I know it’s nearly working because I see new admin options and Jetpack’s infinite scroll footer. (It added an annoying “Proudly powered by WordPress…” credit in the website footer.) Unfortunately my blog and archives are still paginated.

Posts page: staging.jeremyborum.com
An archive page: staging.jeremyborum.com/2016/

In functions.php I added:
`add_theme_support( ‘infinite-scroll’, array(
‘container’ => ‘top’,
‘type’ => ‘scroll’,
‘wrapper’ => ‘true’,
‘footer’ => ‘false’,
‘footer_widgets’ => ‘false’,
‘footer_callback’ => ‘no_jetpack_footer’
) );
// (kill Jetpack’s annoying popup footer)
function no_jetpack_footer() { ?>

<?php }` It appeared to be working because new settings are available in the WP admin: In **Settings > Reading** “Infinite Scroll Behavior” is checked. In **Jetpack > Settings** infinite scroll is set to “Load more posts as the reader scrolls down” and “Lazy load images” is enabled. **Could it be that `‘container’ => ‘top’` is incorrect for the X theme?** In a page’s source code, just before all of the `` tags that contain each post, is `<div class="x-main full" role="main”>`. It seems like I should name this div as the container for infinite scroll instead of `‘top’`, but that div doesn’t have an ID. I also tried the following, none of which worked: `'container' => 'x-root' 'container' => 'x-main' 'container' => 'content'` All help and suggestions are appreciated. Many thanks.

Hi there,

I wonder ID the container which it is said in the Jetpack should be as the CSS selector? So for example #top or x-main for the class.

Honestly, we are not familiar how the infinite scroll functionality works in Jetpack. But as the theme related wrappers, you are on the right track. .x-main can be a good one.

Thank you.

My suspicions about the 'container' parameter were wrong. I gave the <div> containing the posts an ID in wp-index.php because X doesn’t give it an ID, only a class. Referencing that new div ID didn’t help Jetpack at all, so the problem is elsewhere.

Hi there,

Unfortunately, we are unable to give further assistance as we do not know about the details fo the plugin. Please contact their support and follow up with them.

I would also check the case with the default WordPress theme to see if I get things right without the X and then if everything is working fine then I would work on the X. But any way you will need the assistance of the plugin developers.

From what we can say you selected the classes or IDs correctly for the theme.

Thank you for your understanding.

I have made some progress and I have almost figured it out, but one thing is still baffling me. It is related to how X renders the posts on the home page with Masonry. Jetpack is working perfectly, but X is not quite behaving.

Infinite scroll is now working correctly on all of my categories and archives.
My Orchestrator category: http://staging.jeremyborum.com/category/orchestrator-news/
A year archive: http://staging.jeremyborum.com/2014/

My home page, however, is not working:
http://staging.jeremyborum.com/the-latest-buzz/

It’s not working because I’m using Masonry for the blog. When I use the standard style, the home page also works.

This the render function I’m using to tell Jetpack how to render the posts. I copied it from wp-index.php.

function jetpack_infinite_scroll_render() {
 $is_filterable_index = is_home() && x_get_option( 'x_ethos_filterable_index_enable' ) == '1';
 if ( $is_filterable_index ) : 
   x_get_view( 'ethos', '_index' );
 else :
   x_get_view( 'global', '_index' );
 endif;
}

Could you please tell me why the Masonry style for the blog breaks the infinite scroll, and how to fix the rendering so that X will be happy?

Thank you very much.

Hi there,

I just checked and it’s working, it’s just taking time to load the next items. Probably because of images, could you try it again and wait for it to load.

Masonry uses javascript and positioning so it might affect the scroll position of jetpack infinite scroll.

Thanks!

Jetpack was going to require some javascript customization to enable infinite scroll in Masonry format, and that’s a bit beyond me. I normally don’t mind learning a bit, but The Grid has a much more attractive and more flexible solutions for masonry layouts. I’ve used The Grid where I want masonry with infinite scroll, and Jetpack infinite scroll is handling all the pages where I want standard format.

S O L V E D

For others, and for my own future reference:

Integrating Jetpack’s infinite scroll into X requires changes in three files:
style.css
functions.php
framework/views/ethos/wp-index.php

See: https://jetpack.com/support/infinite-scroll/

Another good tutorial: https://www.cssigniter.com/how-to-implement-jetpacks-infinite-scroll-on-your-blog/

FIRST:
Jetpack needs to know the ID of the div which contains all the posts. In X that div has a class of x-main but has no ID by default. Without an ID it won’t work. To fix it, name the ID content. In ethos/wp-index.php change this line:
<div class="<?php x_main_content_class(); ?>" role="main">
into this:
<div id="content" class="<?php x_main_content_class(); ?>" role="main">

SECOND:
Add this code to functions.php. If you have a footer you’ll need to change those options. If you want a Show More button you’ll also need to change the options. See the first link above.

// Add theme support for Jetpack infinite scroll
// =======================
    add_action( 'after_setup_theme', 'jetpack_infinite_scroll_init' );
    function jetpack_infinite_scroll_init() {
      add_theme_support( 'infinite-scroll', array(
        'container'      => 'content',
        'render'         => 'jetpack_infinite_scroll_render',
        'posts_per_page' => get_option( 'posts_per_page' ),
        'footer' 		 => false,
        'footer_widgets' => false,
        'footer_callback' => 'no_jetpack_footer',
      ) );
    }
// Render the posts
function jetpack_infinite_scroll_render() {
  $is_filterable_index = is_home() && x_get_option( 'x_ethos_filterable_index_enable' ) == '1';
  if ( $is_filterable_index ) : 
    x_get_view( 'ethos', '_index' );
  else :
    x_get_view( 'global', '_index' );
  endif;
}
// (remove Jetpack's annoying popup footer)
function no_jetpack_footer() { ?> 
    <div id="infinite-footer"></div> 
<?php }
// =======================

THIRD:
Add this code to style.css to hide the pagination controls since we no longer need them.

/* Hide pagination when Jetpack's infinite scroll is in use */
.infinite-scroll .x-pagination {
	display: none;
} 

FOURTH:
Go to Admin > Settings > Reading and select “Load posts as you scroll”

Go to Admin > Jetpack > Settings and select “Load more posts as the reader scrolls down”
If you have footers that you care about, select “Load more posts in page with a button” instead

If it’s still not working the way you would like, one of the two links at the top of this post will help you sort it out.

As I mentioned in the post just above this one, Jetpack’s infinite scroll can work with Masonry layout, but only with some additional Javascript modifications. I didn’t bother because The Grid looks much nicer.

I hope this helps somebody…

2 Likes

WoW! Thank you for taking the time and sharing this with us and our customers. This will be a great opportunity for our other users to implement the feature.

We truly appreciate your time and contribution to our community.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.