kylephillips / favorites

Simple and flexible favorite buttons for any WordPress post type.
https://favoriteposts.com
222 stars 85 forks source link

Limit number of favorites returned #81

Open jdozierezell opened 6 years ago

jdozierezell commented 6 years ago

Is there a way to limit the number of favorites returned by the [user_favorites] shortcode? The goal is to add a partial list of favorites to a dashboard with a "see all favorites" button that would link to the full list. Thanks!

CHEWX commented 6 years ago

@jdozierezell There doesn't look to be any options, I think it should be added though.

As an interim measure. You could output into a <ul class="favorites-list"><li></li></ul> list.

Then do some CSS that only shows the first 5 for example.

.favorites-list li:nth-of-type(1n+6) { display: none; }

Then the JavaScript button to show more.

$('.js-load-more').on('click', function(e) {

    e.preventDefault();

    var $btn = $(this);
    var $items = $('.favorites-list li').filter(':hidden:lt(5)');

    $items.show();

    if( $('.favorites-list li').filter(":hidden").length == 0 ) {
        $btn.remove();
    }

});

Untested, but that should work.