texnixe / kirby3-similar

Find similar collection items based on similarity
28 stars 2 forks source link

Limit number of results #4

Closed anthonymasure closed 1 year ago

anthonymasure commented 2 years ago

Thanks for the plugin! How can I limit the number of results?

texnixe commented 2 years ago

You can do that with standard Kirby methods:

$similarPages = $page->similar($options)->limit(5);
anthonymasure commented 2 years ago

Sorry to ask for details, my current code is here and I don't know how to proceed. Thanks a lot for helping me.

        if (is_array($similarPages) || is_object($similarPages)) {
        $first = true; 
        foreach($similarPages as $article) {
texnixe commented 2 years ago

What's the purpose of the if statement?

All you need is

        foreach($similarPages->llimit(5) as $article) {
texnixe commented 1 year ago

Closing this as this doesn't seem to be an issue with the plugin