<p>Try this:</p>
<p>{{ sprig('_layouts/_categories/_loadMore', {limit: 6, category: category}) }}</p>
<p>{{ sprig.script }}</p>
<p>After query category is not defined.</p>

CC BY-SA 4.0
2020-07-18T13:53:49.303Z
2020-07-18T13:53:49.303Z
Pavel Pavlovich
<p>I am trying out Sprig's <a href="https://putyourlightson.com/sprig-cookbook?page=2#load-more" rel="nofollow noreferrer">&quot;Load More&quot; Recipe</a> and I am trying to call up entries that are related to the current category page. But when I add <code>.relatedTo(category)</code> to the entry model, it doesn't work–it still just shows all the entries in the channel. I've used this <code>.relatedTo(category)</code> method elsewhere on the page (not using Sprig) and it works just fine. How can I call up only the entries that match the current category page in this Sprig recipe?</p>
<p><strong>_category.twig</strong></p>
<pre><code>{{ sprig('_layouts/_categories/_loadMore', {limit: 6}) }}
{{ sprig.script }}
</code></pre>
<p><strong>_loadMore.twig</strong></p>
<pre><code>{% set offset = offset ?? 6 %}
{% set limit = limit ?? 10 %}

{% set entries = craft.entries.section('aBetterPost').offset(offset).limit(limit).relatedTo(category).all() %}

{% for entry in entries %}

    &lt;a href=&quot;{{ entry.url }}&quot; class=&quot;more-post&quot;&gt;
        &lt;div class=&quot;more-post-img-wrap&quot;&gt;
            {% set featuredImage = entry.featuredImage.one() %}
            &lt;img src=&quot;{{ featuredImage.getUrl }}&quot; class=&quot;more-post-img&quot;&gt;
            &lt;div class=&quot;red-overlay&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div class=&quot;more-post-content&quot;&gt;
            &lt;div class=&quot;more-post-title&quot;&gt;
                &lt;h3&gt;{{ entry.title }}&lt;/h3&gt;
            &lt;/div&gt;
            &lt;div class=&quot;next-icon&quot;&gt;
                &lt;i class=&quot;fas fa-chevron-right&quot;&gt;&lt;/i&gt;
            &lt;/div&gt;
        &lt;/div&gt;
    &lt;/a&gt;

{% endfor %}

            
{% if entries %}

&lt;div class=&quot;load-button-wrap&quot; s-target=&quot;this&quot; s-swap=&quot;outerHTML&quot;&gt;
    &lt;input type=&quot;hidden&quot; name=&quot;offset&quot; value=&quot;{{ offset + limit }}&quot;&gt;
    &lt;button class=&quot;load-button&quot; sprig&gt;Load More&lt;/button&gt;
&lt;/div&gt;

{% endif %}

</code></pre>

<craft3><plugins><categories><relatedto>
How to use categories with Sprig's "Load More" recipe
# How to use categories with Sprig's "Load More" recipe

(Asked by: username_0 on 2020-07-18)

I am trying out Sprig's "Load More" Recipe and I am trying to call up entries that are related to the current category page. But when I add .relatedTo(category) to the entry model, it doesn't work–it still just shows all the entries in the channel. I've used this .relatedTo(category) method elsewhere on the page (not using Sprig) and it works just fine. How can I call up only the entries that match the current category page in this Sprig recipe?
_category.twig
{{ sprig('_layouts/_categories/_loadMore', {limit: 6}) }}
{{ sprig.script }}

_loadMore.twig
{% set offset = offset ?? 6 %}
{% set limit = limit ?? 10 %}

{% set entries = craft.entries.section('aBetterPost').offset(offset).limit(limit).relatedTo(category).all() %}

{% for entry in entries %}

    
        
            {% set featuredImage = entry.featuredImage.one() %}
            
            
        
        
            
                {{ entry.title }}
            
            
                
            
        
    

{% endfor %}

            
{% if entries %}


    
    Load More


{% endif %}

**Tags:** craft3, plugins, categories, relatedto

---

## 1 answers

### Answer by username_1 on 2020-07-18. Score: 2 | Accepted answer

Try this:

{{ sprig('\_layouts/\_categories/\_loadMore', {limit: 6, category: category}) }}

{{ sprig.script }}

After query category is not defined.


---

