ajax – Hide load more button when no more posts to show using Timber
I applied on my listings pages a load more button using Javascript. However, I can’t manage to hide the button when there are no more articles to load. Could you help me please ? For the precision, my theme is a Timber-based.
The markup :
”’
{% for post in posts %}
{% include “tease.twig” %}
{% endfor %}
Load older posts ↓
”’
Here’s my code :
”’
jQuery(‘#articles’).on(‘click’, ‘#load-older-posts’, function(e) {
// prevent new page load
e.preventDefault();
// store next page number
var next_page = jQuery(this).attr(‘href’);
// remove older posts button from DOM
jQuery(this).remove();
// ajax older posts below existing posts
jQuery(‘#articles’).append(
jQuery(”).load(next_page + ‘ #articles’)
);
});
”’
Did you have an idea to solve this issue ?
Thanks you 🙂
Leave an answer