Saturday, January 14, 2023
HomeWordPress Developmentajax - Disguise load extra button when no extra posts to indicate...

ajax – Disguise load extra button when no extra posts to indicate utilizing Timber


I utilized on my listings pages a lot more button utilizing Javascript. Nevertheless, I am unable to handle to cover the button when there are not any extra articles to load. May you assist me please ? For the precision, my theme is a Timber-based.

The markup :

<div id="articles">
    {% for publish in posts %}
        {% embrace "tease.twig" %}
    {% endfor %}
    <a id="load-older-posts" href="{{ pagination.subsequent.hyperlink }}">
        Load older posts ↓
    </a>
</div>

Here is my code :

jQuery('#articles').on('click on', '#load-older-posts', perform(e) {
    // stop new web page load
    e.preventDefault();
    // retailer subsequent web page quantity
    var next_page = jQuery(this).attr('href');
    // take away older posts button from DOM
    jQuery(this).take away();
    // ajax older posts beneath present posts
    jQuery('#articles').append(
      jQuery('<div class="container" />').load(next_page + ' #articles')     
  );
  });

Did you may have an thought to unravel this subject ?

Thanks you 🙂

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments