<p>So, the solution, as provided by @Maverick in their comment above, is just to pass the variable as a query param (<code>?cat=foo</code>), and check for that query param's value in the template.</p>

CC BY-SA 4.0
2020-03-02T16:18:03.830Z
2020-03-02T16:18:03.830Z
Sandwich
<p>I have a list of entries, with an option to filter them by categories.</p>

<p>If no filter is applied, clicking an entry should (and does) take you to the permalink URL for that entry, as defined in the section settings:</p>

<pre><code>&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;
</code></pre>

<p>Results in:</p>

<pre class="lang-html prettyprint-override"><code>&lt;a href="/beverages/gin"&gt;Gin&lt;/a&gt;
</code></pre>

<p>However, if a filter <em>is</em> applied, I'd like to "remember" the category, and apply it to the entry's <code>{{ entry.getNext() }}</code>-style pagination.</p>

<p>In other words, imagine a "Consumables" section, with entries of "Gin", "Lasagne", "Noodles", &amp; "Vodka" (with the obvious categories of "Beverages" and "Food"). You filter the entries on the listing page by the "Beverages" category, &amp; click on the "Gin" entry therein. What I want is for the "Next Entry" link on Gin's page to go to "Vodka", not "Lasagne".</p>

<p>So far, the solution I came up with is to modify the URL for when entries are filtered so that the applied filter results in a URL of <code>/consumables/category/beverages</code>. I also have a route set up so that when a fourth segment is present, it tries to match it up with an entry, eg. <code>/consumables/category/beverages/gin</code>.</p>

<p>Now, I don't know if this is the best solution for this issue, but if it is, the remaining problem is figuring out how to modify the links to the entries on filtered pages so that they include the category. Something like <code>{{ entry.url('consumables/category/' ~ entry.category)</code> would be nice, but it doesn't seem to work like that.</p>

CC BY-SA 4.0
2020-01-27T21:21:46.683Z
Send it with a query param and check if there is a set query param when page is opened.
Maverick
CC BY-SA 4.0
2020-01-28T09:19:08.963Z
@Maverick   I.... you know how sometimes your brain sees the answer clear as day right in front of you? Yeah, that wasn't me yesterday. Thanks!!
Sandwich
CC BY-SA 4.0
2020-01-30T00:48:12.197Z
Can you add your solution as an official answer?
Brad Bell
<templating><categories><url>
How can I retain entry category filtering on entry pages' pagination
# How can I retain entry category filtering on entry pages' pagination

(Asked by: username_0 on 2020-01-27)

I have a list of entries, with an option to filter them by categories.
If no filter is applied, clicking an entry should (and does) take you to the permalink URL for that entry, as defined in the section settings:
{{ entry.title }}

Results in:
Gin

However, if a filter is applied, I'd like to "remember" the category, and apply it to the entry's {{ entry.getNext() }}-style pagination.
In other words, imagine a "Consumables" section, with entries of "Gin", "Lasagne", "Noodles", & "Vodka" (with the obvious categories of "Beverages" and "Food"). You filter the entries on the listing page by the "Beverages" category, & click on the "Gin" entry therein. What I want is for the "Next Entry" link on Gin's page to go to "Vodka", not "Lasagne".
So far, the solution I came up with is to modify the URL for when entries are filtered so that the applied filter results in a URL of /consumables/category/beverages. I also have a route set up so that when a fourth segment is present, it tries to match it up with an entry, eg. /consumables/category/beverages/gin.
Now, I don't know if this is the best solution for this issue, but if it is, the remaining problem is figuring out how to modify the links to the entries on filtered pages so that they include the category. Something like {{ entry.url('consumables/category/' ~ entry.category) would be nice, but it doesn't seem to work like that.

**Tags:** templating, categories, url
> **Comments:**
> **username_1**: Send it with a query param and check if there is a set query param when page is opened.  
> **username_0**: @Maverick   I.... you know how sometimes your brain sees the answer clear as day right in front of you? Yeah, that wasn't me yesterday. Thanks!!  
> **username_2**: Can you add your solution as an official answer?  

---

## 1 answers

### Answer by username_0 on 2020-03-02. Score: 1 | Accepted answer

So, the solution, as provided by @Maverick in their comment above, is just to pass the variable as a query param (`?cat=foo`), and check for that query param's value in the template.


---

