I've been able to successfully filter a set of entries by category, and also include pagination for the complete set of entries (in this case so 6 are displayed per page). But once a category filter is applied the pagination does not affect the filtered output, so for example, if a filter is applied that results in only 1 entry being displayed the pagination controls still show 2 pages (for 12 entries in total). Then clicking on previous/next page (which of course users are bound to do!) re-sets the filter to show all results.

I can't work out a solution.... :(

If someone could please have a look and suggest a solution I would be very grateful!

Many thanks.

{% if craft.request.getParam('category') is not null %}

  {% set category = craft.categories.slug(craft.request.getParam('category')) %}
  {% paginate craft.entries.section('caseStudies').relatedTo(category).limit(6) as pageInfo, casestudies %}

{% else %}

  {% set casestudies = craft.entries.section('caseStudies').find() %}
  {% paginate craft.entries.section('caseStudies').limit(6) as pageInfo, casestudies %}

{% endif %}

<ul class="features">
  {% for category in craft.categories.group('industriesAndSectors').find() %}
    <li><a href="{{craft.request.url}}/?category={{ category.slug }}" title="{{ category.title}}">{{ category.title}}</a></li>
  {% endfor %}
  <li><a href="/case-studies/" title="All Types">All Types</a></li>

{% for casestudy in casestudies %}
  <div class="col-1-4">
    {% set photo = casestudy.caseStudyImage.first() %}
    {% if photo %}
      <a href="{{ casestudy.url }}"><img src="{{ photo.url('thumbnail334x334') }}" alt="{{ casestudy.title}}" ></a>
    {% endif %}
    <div class="white padded">
      <h4><a href="{{ casestudy.url }}">{{ casestudy.title}}</a></h4>
      {# {{ entry.body.getPage(1) }} #}
{% endfor %}

<!-- pagination -->

<ul class="inline-list clear-both">
  {% if pageInfo.prevUrl %} <li><a href="{{ pageInfo.prevUrl }}"><i class="icon-chevron-left"></i></a></li>{% endif %}

  {% for page, url in pageInfo.getPrevUrls() %}<li><a class="pagination_pageno" href="{{ url }}" title="{{ page }}">{{ page }}</a></li>{% endfor %}

  <li class="pagination_pageno">{{ pageInfo.currentPage }}</li>

  {% for page, url in pageInfo.getNextUrls() %}<li><a class="pagination_pageno" href="{{ url }}" title="{{ page }}">{{ page }}</a></li>{% endfor %}

  {% if pageInfo.nextUrl %} <li><a href="{{ pageInfo.nextUrl }}"><i class="icon-chevron-right"></i></a></li>{% endif %}
<!-- / pagination -->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.