1

Some of my entries have the same entry.title. At the frontend, I would like to display these entries only once. This works with the following code:

{% set entries = craft.entries().section('produkte').relatedTo(category) %}
{% set existingtitle = [] %}
 {% for entry in entries %}
  {% if entry.title not in existingtitle %}        
    {{ Display the Results }}
  {% endif %}
  {% set existingtitle = existingtitle|merge([entry.title]) %}
 {% endfor %}

My question is: How can I then paginate these results? For example 9 entries per page? If I paginate before the "if" condition gives me not the required result. Any help or tips are highly appreciated!

  • 1
    For issue 1 you could create another query on your second page using the offset function. So .limit(1).offer(8). This should get you the 9th entry. Also I would consider looping through your returned data and maybe reordering into a new array with the title as a key maybe. – Dean Sanderson Aug 9 '19 at 18:00
2

You can build an array of the filtered results, then paginate that.

{% set entries = craft.entries().section('produkte').relatedTo(category) %}
{% set filteredEntries = [] %}
{% set existingtitle = [] %}
{% for entry in entries %}
    {% if entry.title not in existingtitle %}
        {% set filteredEntries = filteredEntries|merge([entry]) %}
    {% endif %}
    {% set existingtitle = existingtitle|merge([entry.title]) %}
{% endfor %}

Then modify this code to paginate array: https://gist.github.com/juban/a55781d49f2f68ec3ca47979bcaaa49a

|improve this answer|||||

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.