blog cards list and infinity scroll pagination

Hello community,

currently, I need to show a list of blog posts with cards like the image below and add an infinite scroll to load more article cards, do you have some documentation how to create the cards and added the infinite scroll ?

thank you.
Best Regards.

Hi @ICaceres,

Thanks for reaching out to the Community!

I wanted to share this infinite scroll tutorial. I found this resource through HubSpot’s blog on infinite scrolling.

You can change the blog listing template by following these steps. If you have access to developers, they can find here the blog template markup.

I also wanted to tag in our subject matter experts to see if they have any advice.

Hi @Jnix284, @Anton, @Teun - Do you have any recommendations or custom module building tips for @ICaceres?

Thank you!

Best,

Kristen

Hi @ICaceres.,

I would create a custom blog listing template with the infinite-scroll script and recent_blog_post function.

Haven’t tested it but it should look something like this:

{% require_head %}
<script src="https://unpkg.com/infinite-scroll@4/dist/infinite-scroll.pkgd.min.js"></script>
<script>
let elem = document.querySelector('.infinite-posts');
let infScroll = new InfiniteScroll( elem, {
 // options
 path: function() {
 // no value returned after 4th loaded page
 if ( this.loadCount < 4 ) {
 let nextIndex = this.loadCount + 2; {# change the number to the amount you'd like to add posts on "load more" click #}
 return `news/blog-p${nextIndex}.html`; {# change this to your post logic #}
 }
}
 append: '.post',
 history: false,
});

</script>
{% end_require_head %}

{% set rec_posts = blog_recent_posts("default", 9999) %}

<div class="infinite-posts">
{% for rec_post in rec_posts %}
<div class="post">
{# write your single post layout here #}
</div>
{% endfor %}
</div>

best,

Anton