<p>The huge advantage of craft over other CMS is the high flexibility and the ability to customize many things. Thus Craft won't provide non changeable <code>&lt;a&gt;</code> tags but links you can change like you want.</p>

<pre><code>{% set country = craft.request.getParam('country') %}
&lt;a href="{{ pageInfo.prevUrl }}?country={{country}}"&gt;Previous Page&lt;/a&gt;
</code></pre>

CC BY-SA 3.0
2017-12-12T21:22:53.127Z
2017-12-12T21:22:53.127Z
Robin Schambach
<p>In most Craft projects I do I'll create a pagination include file so anything I need that requires pagination, I can just include that and I get the same pagination pattern anywhere within my site when I need it.</p>

<p>While you do have to set the country attribute with each link, sometimes it might get a little tedious to do this manually or you may expand your attributes to include other options, like <code>?country=123&amp;distance=50</code>.</p>

<p>This is where Craft's <code>craft.request.getQueryStringWithoutPath()</code> comes into play. In Craft 3 this has been changed to <code>craft.app.request.queryStringWithoutPath</code>. But you could do something like this:</p>

<pre><code>{% if craft.request.getQueryStringWithoutPath() %}
  {% set queryString = "?" ~ craft.request.getQueryStringWithoutPath() %}
{% endif %}

&lt;a href="{{ paginate.prevUrl }}{% if queryString is defined %}{{ queryString }}{% endif %}"&gt;Previous&lt;/a&gt;
</code></pre>

<p>Then no matter what URL attributes you have, they'll always be included within your pagination links.</p>

CC BY-SA 3.0
2017-12-13T15:39:52.753Z
Thanks for the tip! I did use a pagination include file on another, more straight-forward project. This project is an older one, but lots of areas need streamlining... this will help!
Steven Thate
CC BY-SA 3.0
2017-12-13T15:34:59.683Z
2017-12-13T15:34:59.683Z
Tim Knight
<p>I have an index page that filters entries based on url query strings, eg: <code>site.com/inductees?county=123</code>.</p>

<p>I put together a very simple pagination setup with next/prev links. However, when I click "next" I am brought to <code>site.com/inductees/p2</code> and I lose my filtered set of entries from the <code>?county=123</code> bit.</p>

<p><strong>How can I get pagination working and keep the query string in my url?</strong></p>

<p>Thanks!</p>

CC BY-SA 3.0
2017-12-12T21:10:25.857Z
Wouldn't it be an option to add the additional parameters to the url `<a href="{{ pageInfo.prevUrl }}?country=123">Previous Page</a>`
Robin Schambach
CC BY-SA 3.0
2017-12-12T21:18:12.590Z
That was excitingly simple. I was thinking of that before I asked this question but assumed it wouldn't work for some reason. Thanks! Make it an answer if you'd like a vote.
Steven Thate
<url><pagination>
Using pagination on a page with url with query string data
# Using pagination on a page with url with query string data

(Asked by: username_0 on 2017-12-12)

I have an index page that filters entries based on url query strings, eg: `site.com/inductees?county=123`.

I put together a very simple pagination setup with next/prev links. However, when I click "next" I am brought to `site.com/inductees/p2` and I lose my filtered set of entries from the `?county=123` bit.

**How can I get pagination working and keep the query string in my url?**

Thanks!

**Tags:** url, pagination

> **Comments:**
> **username_1**: Wouldn't it be an option to add the additional parameters to the url `<a href="{{ pageInfo.prevUrl }}?country=123">Previous Page</a>`  
> **username_0**: That was excitingly simple. I was thinking of that before I asked this question but assumed it wouldn't work for some reason. Thanks! Make it an answer if you'd like a vote.  

---

## 2 answers

### Answer by username_1 on 2017-12-12. Score: 3 | Accepted answer

The huge advantage of craft over other CMS is the high flexibility and the ability to customize many things. Thus Craft won't provide non changeable  tags but links you can change like you want.
{% set country = craft.request.getParam('country') %}
Previous Page


---

### Answer by username_2 on 2017-12-13. Score: 9

In most Craft projects I do I'll create a pagination include file so anything I need that requires pagination, I can just include that and I get the same pagination pattern anywhere within my site when I need it.
While you do have to set the country attribute with each link, sometimes it might get a little tedious to do this manually or you may expand your attributes to include other options, like ?country=123&distance=50.
This is where Craft's craft.request.getQueryStringWithoutPath() comes into play. In Craft 3 this has been changed to craft.app.request.queryStringWithoutPath. But you could do something like this:
{% if craft.request.getQueryStringWithoutPath() %}
  {% set queryString = "?" ~ craft.request.getQueryStringWithoutPath() %}
{% endif %}

Previous

Then no matter what URL attributes you have, they'll always be included within your pagination links.

> **Comments:**
> **username_0**: Thanks for the tip! I did use a pagination include file on another, more straight-forward project. This project is an older one, but lots of areas need streamlining... this will help!  

---

