Answers.Body: <p>Using the <a href="https://craftcms.com/docs/templating/paginate" rel="nofollow">pagination helper</a> might be a cleaner way to achieve your desired results. It would go something like this:</p>
  
  <pre><code>{% paginate craft.entries.section('news').order('postDate').relatedTo({targetElement:categoryId}).limit(5) as entries %}
      {% for item in entries %}
          {# your item code goes here #}
      {% endfor %}
      {% if paginate.prevUrl %}
          &lt;a class="button left" href="{{ paginate.prevUrl }}"&gt;Previous&lt;/a&gt;
      {% endif %}
      {% if paginate.nextUrl %}
          &lt;a class="button right" href="{{ paginate.nextUrl }}"&gt;Next&lt;/a&gt;
      {% endif %}
  {% endpaginate %}
  </code></pre>
  
  <p>By using the <code>relatedTo({targetElement:categoryId})</code> param you will stay in the same category as you paginate entries. This pagination helper handles the urls.  So we are just accessing the <code>paginate.prevUrl &amp; paginate.nextUrl</code> variables provided by the helper.  All you need to do is make sure the categoryId is set to the category you need and set the limit to the number of items to paginate by.</p>
  
  <p>--</p>
  
  <p>For your particular setup I would use two templates.  One for the News landing page and one for the category landing. The news landing page will paginate all News entries. </p>
  
  <p>Once a category is clicked and now uses the template specified in the category setup page, you will limit paginated entries to the current category.  The variable <code>category</code> is reserved for those templates so you can access anything variable associated with the current category you are on. You will only notice slight difference between the two. The Category Template adds the <code>relatedTo({targetElement:category.id})</code> criteria in addition to setting the active category class.</p>
  
  <p>Here are both templates.</p>
  
  <p><strong>News Landing Template</strong></p>
  
  <pre><code>{% set title = entry.title %}
  {% set description = entry.body | striptags %}
  
  {% extends "_layout" %}
  
  {% block content %}
  
    &lt;div class="heading"&gt;
      &lt;h1&gt;{{ newsHeader.header }}&lt;/h1&gt;
    &lt;/div&gt;
  
    &lt;div class="filter-bar news"&gt;
        &lt;div class="container"&gt;
          &lt;ul class="largenav"&gt;
              &lt;li&gt;&lt;a href="/news"&gt;All&lt;/a&gt;&lt;/li&gt;
              {% for topic in craft.categories.group('newsCategories') %}
                &lt;li&gt;
                  &lt;a href="{{ topic.url }}"&gt;{{ topic.title }}&lt;/a&gt;
                &lt;/li&gt;
              {% endfor %}
          &lt;/ul&gt;
          &lt;div class="select tinynav"&gt;
              &lt;a href="#" id="select-toggle"&gt;All&lt;/a&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a data-value="{{ siteUrl }}news" href="#"&gt;All&lt;/a&gt;&lt;/li&gt;
                  {% for topic in craft.categories.group('newsCategories') %}
                    &lt;li&gt;
                      &lt;a href="#" data-value="{{ topic.url }}"&gt;{{ topic.title }}&lt;/a&gt;
                    &lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
          &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
  
      {% paginate craft.entries.section('news').order('postDate').limit(5) as entries %}
        &lt;ul class="wrapper newspage"&gt;
          {% for item in entries %}
            &lt;li class="news-item"&gt;
              &lt;h1&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h1&gt;
                &lt;h5 class="meta"&gt;{{ entry.postDate|date("F j, Y") }} &amp;nbsp;|&amp;nbsp;
  
                    {% if entryCategories | length %}
                      {% for topic in entryCategories %}
                        &lt;a href="{{ topic.url }}"&gt;{{ topic.title }}&lt;/a&gt;
                      {% endfor %}
                    {% endif %}
                &lt;/h5&gt;
              &lt;p&gt;{{ entry.body }}&lt;/p&gt;
            &lt;/li&gt;  
          {% endfor %}
        &lt;/ul&gt;
        &lt;li class="news-item"&gt;
          {% if paginate.prevUrl %}
              &lt;a class="button left" href="{{ paginate.prevUrl }}"&gt;Previous&lt;/a&gt;
          {% endif %}
          {% if paginate.nextUrl %}
              &lt;a class="button right" href="{{ paginate.nextUrl }}"&gt;Next&lt;/a&gt;
          {% endif %}
  
          &lt;div class="clear"&gt;&lt;/div&gt;
        &lt;/li&gt;
      {% endpaginate %}
    &lt;/ul&gt;
  
  {% endblock %}
  </code></pre>
  
  <p><strong>Category Template</strong></p>
  
  <pre><code>{% set title = entry.title %}
  {% set description = entry.body | striptags %}
  
  {% extends "_layout" %}
  
  {% block content %}
  
    &lt;div class="heading"&gt;
      &lt;h1&gt;{{ newsHeader.header }}&lt;/h1&gt;
    &lt;/div&gt;
  
    &lt;div class="filter-bar news"&gt;
        &lt;div class="container"&gt;
          &lt;ul class="largenav"&gt;
              &lt;li&gt;&lt;a href="/news"&gt;All&lt;/a&gt;&lt;/li&gt;
              {% for topic in craft.categories.group('newsCategories') %}
                &lt;li&gt;
                  &lt;a href="{{ topic.url }}" {% if category.url == topic.url %}class="active"{% endif %}&gt;{{ topic.title }}&lt;/a&gt;
                &lt;/li&gt;
              {% endfor %}
          &lt;/ul&gt;
          &lt;div class="select tinynav"&gt;
              &lt;a href="#" id="select-toggle"&gt;All&lt;/a&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a data-value="{{ siteUrl }}news" href="#"&gt;All&lt;/a&gt;&lt;/li&gt;
                  {% for topic in craft.categories.group('newsCategories') %}
                    &lt;li&gt;
                      &lt;a href="#" data-value="{{ topic.url }}"&gt;{{ topic.title }}&lt;/a&gt;
                    &lt;/li&gt;
                  {% endfor %}
              &lt;/ul&gt;
          &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
  
      {% paginate craft.entries.section('news').order('postDate').relatedTo({targetElement:category.id}).limit(5) as entries %}
        &lt;ul class="wrapper newspage"&gt;
          {% for item in entries %}
            &lt;li class="news-item"&gt;
              &lt;h1&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h1&gt;
                &lt;h5 class="meta"&gt;{{ entry.postDate|date("F j, Y") }} &amp;nbsp;|&amp;nbsp;
  
                    {% if entryCategories | length %}
                      {% for topic in entryCategories %}
                        &lt;a href="{{ topic.url }}"&gt;{{ topic.title }}&lt;/a&gt;
                      {% endfor %}
                    {% endif %}
                &lt;/h5&gt;
              &lt;p&gt;{{ entry.body }}&lt;/p&gt;
            &lt;/li&gt;  
          {% endfor %}
        &lt;/ul&gt;
        &lt;li class="news-item"&gt;
          {% if paginate.prevUrl %}
              &lt;a class="button left" href="{{ paginate.prevUrl }}"&gt;Previous&lt;/a&gt;
          {% endif %}
          {% if paginate.nextUrl %}
              &lt;a class="button right" href="{{ paginate.nextUrl }}"&gt;Next&lt;/a&gt;
          {% endif %}
  
          &lt;div class="clear"&gt;&lt;/div&gt;
        &lt;/li&gt;
      {% endpaginate %}
    &lt;/ul&gt;
  
  {% endblock %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-05T13:35:15.140Z
Answers.Text: Hi @aran, thanks for your help. I tried this using this code while replacing "categoryID" with one of the category ID's, and it didn't really work. When you click Next or Previous, it just goes to the same post over and over again. Is there a way to create a variable that gets the current category ID of the post the user is on, and use a variable instead of a static ID?
  
  Here is the page: http://monderer.com/news/announcements
Answers.UserDisplayName: Charlotte H
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-05T15:25:36.353Z
Answers.Text: Are the sub navigation items categories, and when clicked they take you to the detail page route for the category?
Answers.UserDisplayName: a-am
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-05T16:39:48.717Z
Answers.Text: the sub navigation items are categories, and they just take you to a list of posts assigned to that category. We just want users to remain in the chosen category when navigating with the Next and Previous buttons.
Answers.UserDisplayName: Charlotte H
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-05T18:52:30.323Z
Answers.Text: Then when you are on at a category url you can use `category.id` to get the current category your on.  So it would be `{targetElement:category.id}`.  Then your paginate helper should always stay in that category.  If this doesn't seem to work for you please post your code and I will take a look.
Answers.UserDisplayName: a-am
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-07T13:06:57.633Z
Answers.Text: Hi @aran, I've changed my question to contain all of the code from the page so you can see what I mean.
Answers.UserDisplayName: Charlotte H
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-07T16:01:08.210Z
Answers.Text: @CharlotteH I have updated my answer as well.
Answers.UserDisplayName: a-am
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-01-04T21:02:00.187Z
Answers.LastActivityDate: 2016-01-07T16:00:43.567Z
Answers.LastEditDate: 2016-01-07T16:00:43.567Z
Answers.UserDisplayName: a-am
Body: <p>I'm new to Craft and am trying to have our entry pagination (next/prev) links go to the next entry within that same category, ordering by date.</p>
  
  <p>So the order part is working as I want it to, it's just remaining in the current category I need help with. Thanks!</p>
  
  <p>Here's what I have so far...</p>
  
  <pre><code>{% set title = entry.title %}
  {% set description = entry.body | striptags %}
  
  {% extends "_layout" %}
  
  {% block content %}
  
  {% set entryCategories = entry.newsCategories %}
  
  {% set thisCategory = '' %}
  
  {% for category in entryCategories %}
  
  {% set thisCategory = category.url %}
  
  {% endfor %}
  
    &lt;div class="heading"&gt;
      &lt;h1&gt;{{ newsHeader.header }}&lt;/h1&gt;
    &lt;/div&gt;
    &lt;div class="filter-bar news"&gt;
        &lt;div class="container"&gt;
          &lt;ul class="largenav"&gt;
              &lt;li&gt;&lt;a href="/news"&gt;All&lt;/a&gt;&lt;/li&gt;{% nav category in     craft.categories.group('newsCategories') %}{% if category.url == thisCategory %}&lt;li class="active"&gt;&lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;&lt;/li&gt;{% else %}&lt;li&gt;&lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;&lt;/li&gt;{% endif %}{% endnav %}
          &lt;/ul&gt;
          &lt;div class="select tinynav"&gt;
              &lt;a href="#" id="select-toggle"&gt;All&lt;/a&gt;
              &lt;ul&gt;
                  &lt;li&gt;&lt;a data-value="{{ siteUrl }}news" href="#"&gt;All&lt;/a&gt;&lt;/li&gt;
                  {% nav category in craft.categories.group('newsCategories') %}
                  &lt;li&gt;&lt;a href="#" data-value="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;&lt;/li&gt;
                  {% endnav %}
          &lt;/div&gt;
        &lt;/div&gt;
    &lt;/div&gt;
  
  
  
    &lt;ul class="wrapper newspage"&gt;
  
          &lt;ul&gt;
          &lt;li class="news-item"&gt;
            &lt;h1&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h1&gt;
            &lt;h5 class="meta"&gt;{{ entry.postDate|date("F j, Y") }} &amp;nbsp;|&amp;nbsp;
  
                {% if entryCategories | length %}
  
                {% for category in entryCategories %}
  
                  &lt;a href="{{ category.url }}"&gt;{{ category.title }}&lt;/a&gt;
  
                {% endfor %}
                {% endif %}
  
              &lt;/h5&gt;
        &lt;p&gt;{{ entry.body }}&lt;/p&gt;
  
      &lt;/li&gt;
      &lt;/ul&gt;
  
      &lt;ul&gt;
              &lt;li class="news-item"&gt;
  
                  {# Set parameters for prev/next elements list #}
                  {% set params = {section: 'news', category: category.title, order: 'postDate'} %}
  
                  {# Get the prev/next elements #}
                  {% set prevEntry = entry.getPrev(params) %}
                  {% set nextEntry = entry.getNext(params) %}
  
                  {# And make sure to only output the links if the element exists #}
                  {% if prevEntry %}&lt;a class="button left" href="{{ prevEntry.url }}"&gt;Previous&lt;/a&gt;{% endif %}
                  {% if nextEntry %}&lt;a class="button right" href="{{ nextEntry.url }}"&gt;Next&lt;/a&gt;{% endif %}
  
                  &lt;div class="clear"&gt;&lt;/div&gt;
              &lt;/li&gt;
        &lt;/ul&gt;
  
  
    &lt;/ul&gt;
  
  {% endblock %}
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-04T19:05:28.180Z
Comments.Text: `it's just remaining in the current category I need help with.` - I'm not following that.  What's the behavior you're expecting and what you are currently seeing?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-04T20:02:14.227Z
Comments.Text: Say you had two categories, Dogs, and Cats. If you were reading a post in the Dog category and clicked Next, it should link to the next post by date within the Dog category. As it is right now, when you click Next, it just goes to the next post by date, without regard for the category.
Comments.UserDisplayName: Charlotte H
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-04T20:38:46.197Z
Comments.Text: So there's a category field on the entries and you only want to grab the entries with a specific category selected?
Comments.UserDisplayName: Brad Bell
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-01-05T13:37:23.277Z
Comments.Text: Yes. So you would only navigate through the posts in one category, until you click on a different category to navigate through. Here's the page link if that helps: http://monderer.com/news/announcements
Comments.UserDisplayName: Charlotte H
Tags: <pagination><query>
Title: Entry Pagination - Group by Current Category and Order by Post Date
ThreadText: # Entry Pagination - Group by Current Category and Order by Post Date
  
  (Asked by: username_0 on 2016-01-04)
  
  I'm new to Craft and am trying to have our entry pagination (next/prev) links go to the next entry within that same category, ordering by date.
  
  So the order part is working as I want it to, it's just remaining in the current category I need help with. Thanks!
  
  Here's what I have so far...
  
  ```
  {% set title = entry.title %}
  {% set description = entry.body | striptags %}
  
  {% extends "_layout" %}
  
  {% block content %}
  
  {% set entryCategories = entry.newsCategories %}
  
  {% set thisCategory = '' %}
  
  {% for category in entryCategories %}
  
  {% set thisCategory = category.url %}
  
  {% endfor %}
  
    <div class="heading">
      <h1>{{ newsHeader.header }}</h1>
    </div>
    <div class="filter-bar news">
        <div class="container">
          <ul class="largenav">
              <li><a href="/news">All</a></li>{% nav category in     craft.categories.group('newsCategories') %}{% if category.url == thisCategory %}<li class="active"><a href="{{ category.url }}">{{ category.title }}</a></li>{% else %}<li><a href="{{ category.url }}">{{ category.title }}</a></li>{% endif %}{% endnav %}
          </ul>
          <div class="select tinynav">
              <a href="#" id="select-toggle">All</a>
              <ul>
                  <li><a data-value="{{ siteUrl }}news" href="#">All</a></li>
                  {% nav category in craft.categories.group('newsCategories') %}
                  <li><a href="#" data-value="{{ category.url }}">{{ category.title }}</a></li>
                  {% endnav %}
          </div>
        </div>
    </div>
  
    <ul class="wrapper newspage">
  
          <ul>
          <li class="news-item">
            <h1><a href="{{ entry.url }}">{{ entry.title }}</a></h1>
            <h5 class="meta">{{ entry.postDate|date("F j, Y") }} &nbsp;|&nbsp;
  
                {% if entryCategories | length %}
  
                {% for category in entryCategories %}
  
                  <a href="{{ category.url }}">{{ category.title }}</a>
  
                {% endfor %}
                {% endif %}
  
              </h5>
        <p>{{ entry.body }}</p>
  
      </li>
      </ul>
  
      <ul>
              <li class="news-item">
  
                  {# Set parameters for prev/next elements list #}
                  {% set params = {section: 'news', category: category.title, order: 'postDate'} %}
  
                  {# Get the prev/next elements #}
                  {% set prevEntry = entry.getPrev(params) %}
                  {% set nextEntry = entry.getNext(params) %}
  
                  {# And make sure to only output the links if the element exists #}
                  {% if prevEntry %}<a class="button left" href="{{ prevEntry.url }}">Previous</a>{% endif %}
                  {% if nextEntry %}<a class="button right" href="{{ nextEntry.url }}">Next</a>{% endif %}
  
                  <div class="clear"></div>
              </li>
        </ul>
  
    </ul>
  
  {% endblock %}
  
  ```
  
  **Tags:** pagination, query
  
  > **Comments:**
  > **username_1**: `it's just remaining in the current category I need help with.` - I'm not following that.  What's the behavior you're expecting and what you are currently seeing?  
  > **username_0**: Say you had two categories, Dogs, and Cats. If you were reading a post in the Dog category and clicked Next, it should link to the next post by date within the Dog category. As it is right now, when you click Next, it just goes to the next post by date, without regard for the category.  
  > **username_1**: So there's a category field on the entries and you only want to grab the entries with a specific category selected?  
  > **username_0**: Yes. So you would only navigate through the posts in one category, until you click on a different category to navigate through. Here's the page link if that helps: http://monderer.com/news/announcements  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_2 on 2016-01-04. Score: 2
  
  Using the [pagination helper](https://craftcms.com/docs/templating/paginate) might be a cleaner way to achieve your desired results. It would go something like this:
  
  ```
  {% paginate craft.entries.section('news').order('postDate').relatedTo({targetElement:categoryId}).limit(5) as entries %}
      {% for item in entries %}
          {# your item code goes here #}
      {% endfor %}
      {% if paginate.prevUrl %}
          <a class="button left" href="{{ paginate.prevUrl }}">Previous</a>
      {% endif %}
      {% if paginate.nextUrl %}
          <a class="button right" href="{{ paginate.nextUrl }}">Next</a>
      {% endif %}
  {% endpaginate %}
  
  ```
  
  By using the `relatedTo({targetElement:categoryId})` param you will stay in the same category as you paginate entries. This pagination helper handles the urls. So we are just accessing the `paginate.prevUrl & paginate.nextUrl` variables provided by the helper. All you need to do is make sure the categoryId is set to the category you need and set the limit to the number of items to paginate by.
  
  --
  
  For your particular setup I would use two templates. One for the News landing page and one for the category landing. The news landing page will paginate all News entries.
  
  Once a category is clicked and now uses the template specified in the category setup page, you will limit paginated entries to the current category. The variable `category` is reserved for those templates so you can access anything variable associated with the current category you are on. You will only notice slight difference between the two. The Category Template adds the `relatedTo({targetElement:category.id})` criteria in addition to setting the active category class.
  
  Here are both templates.
  
  **News Landing Template**
  
  ```
  {% set title = entry.title %}
  {% set description = entry.body | striptags %}
  
  {% extends "_layout" %}
  
  {% block content %}
  
    <div class="heading">
      <h1>{{ newsHeader.header }}</h1>
    </div>
  
    <div class="filter-bar news">
        <div class="container">
          <ul class="largenav">
              <li><a href="/news">All</a></li>
              {% for topic in craft.categories.group('newsCategories') %}
                <li>
                  <a href="{{ topic.url }}">{{ topic.title }}</a>
                </li>
              {% endfor %}
          </ul>
          <div class="select tinynav">
              <a href="#" id="select-toggle">All</a>
              <ul>
                  <li><a data-value="{{ siteUrl }}news" href="#">All</a></li>
                  {% for topic in craft.categories.group('newsCategories') %}
                    <li>
                      <a href="#" data-value="{{ topic.url }}">{{ topic.title }}</a>
                    </li>
                  {% endfor %}
              </ul>
          </div>
        </div>
    </div>
  
      {% paginate craft.entries.section('news').order('postDate').limit(5) as entries %}
        <ul class="wrapper newspage">
          {% for item in entries %}
            <li class="news-item">
              <h1><a href="{{ entry.url }}">{{ entry.title }}</a></h1>
                <h5 class="meta">{{ entry.postDate|date("F j, Y") }} &nbsp;|&nbsp;
  
                    {% if entryCategories | length %}
                      {% for topic in entryCategories %}
                        <a href="{{ topic.url }}">{{ topic.title }}</a>
                      {% endfor %}
                    {% endif %}
                </h5>
              <p>{{ entry.body }}</p>
            </li>  
          {% endfor %}
        </ul>
        <li class="news-item">
          {% if paginate.prevUrl %}
              <a class="button left" href="{{ paginate.prevUrl }}">Previous</a>
          {% endif %}
          {% if paginate.nextUrl %}
              <a class="button right" href="{{ paginate.nextUrl }}">Next</a>
          {% endif %}
  
          <div class="clear"></div>
        </li>
      {% endpaginate %}
    </ul>
  
  {% endblock %}
  
  ```
  
  **Category Template**
  
  ```
  {% set title = entry.title %}
  {% set description = entry.body | striptags %}
  
  {% extends "_layout" %}
  
  {% block content %}
  
    <div class="heading">
      <h1>{{ newsHeader.header }}</h1>
    </div>
  
    <div class="filter-bar news">
        <div class="container">
          <ul class="largenav">
              <li><a href="/news">All</a></li>
              {% for topic in craft.categories.group('newsCategories') %}
                <li>
                  <a href="{{ topic.url }}" {% if category.url == topic.url %}class="active"{% endif %}>{{ topic.title }}</a>
                </li>
              {% endfor %}
          </ul>
          <div class="select tinynav">
              <a href="#" id="select-toggle">All</a>
              <ul>
                  <li><a data-value="{{ siteUrl }}news" href="#">All</a></li>
                  {% for topic in craft.categories.group('newsCategories') %}
                    <li>
                      <a href="#" data-value="{{ topic.url }}">{{ topic.title }}</a>
                    </li>
                  {% endfor %}
              </ul>
          </div>
        </div>
    </div>
  
      {% paginate craft.entries.section('news').order('postDate').relatedTo({targetElement:category.id}).limit(5) as entries %}
        <ul class="wrapper newspage">
          {% for item in entries %}
            <li class="news-item">
              <h1><a href="{{ entry.url }}">{{ entry.title }}</a></h1>
                <h5 class="meta">{{ entry.postDate|date("F j, Y") }} &nbsp;|&nbsp;
  
                    {% if entryCategories | length %}
                      {% for topic in entryCategories %}
                        <a href="{{ topic.url }}">{{ topic.title }}</a>
                      {% endfor %}
                    {% endif %}
                </h5>
              <p>{{ entry.body }}</p>
            </li>  
          {% endfor %}
        </ul>
        <li class="news-item">
          {% if paginate.prevUrl %}
              <a class="button left" href="{{ paginate.prevUrl }}">Previous</a>
          {% endif %}
          {% if paginate.nextUrl %}
              <a class="button right" href="{{ paginate.nextUrl }}">Next</a>
          {% endif %}
  
          <div class="clear"></div>
        </li>
      {% endpaginate %}
    </ul>
  
  {% endblock %}
  
  ```
  
  > **Comments:**
  > **username_0**: Hi @aran, thanks for your help. I tried this using this code while replacing "categoryID" with one of the category ID's, and it didn't really work. When you click Next or Previous, it just goes to the same post over and over again. Is there a way to create a variable that gets the current category ID of the post the user is on, and use a variable instead of a static ID?  Here is the page: http://monderer.com/news/announcements  
  > **username_2**: Are the sub navigation items categories, and when clicked they take you to the detail page route for the category?  
  > **username_0**: the sub navigation items are categories, and they just take you to a list of posts assigned to that category. We just want users to remain in the chosen category when navigating with the Next and Previous buttons.  
  > **username_2**: Then when you are on at a category url you can use `category.id` to get the current category your on.  So it would be `{targetElement:category.id}`.  Then your paginate helper should always stay in that category.  If this doesn't seem to work for you please post your code and I will take a look.  
  > **username_0**: Hi @aran, I've changed my question to contain all of the code from the page so you can see what I mean.  
  > **username_2**: @username_0 I have updated my answer as well.  
  
  ---
  
  