<p>It won't work with <code>getPrev</code> and <code>getNext</code>, as they only work with ElementCriteriaModels and not with an array of Entry models.</p>

<p>But that is what you get returned from the plugin. Supersort converts your <code>craft.entries</code> ElementCriteriaModel into an array of Entry models. This is necessary so that it can do the sorting.</p>

<p>The only workaround I know of would be to get the IDs of your supersorted entries and pass them to the ID param of a new ElementCriteriaModel.</p>

<pre><code>{% set entries = craft.entries.section('sectionName').type('entryType') %}
{% set entriesSorted = entries|supersort('natsortAs', '{title}') %}

{% set entryIds = [] %}
{% for entry in entriesSorted %}
    {% set entryIds = entryIds|merge([entry.id]) %}
{% endfor %}

{% set arrowCriteria = craft.entries.id(entryIds).fixedOrder(true) %}
</code></pre>

<p>Now you have an ElementCriteriaModel <code>arrowCriteria</code>, prepared to get entries in the desired sort order. So now you can use <code>arrowCriteria</code> with your entry methods.</p>

<pre><code>{% set prevEntry = entry.getPrev(arrowCriteria) %}
{% set nextEntry = entry.getNext(arrowCriteria) %}

{% if prevEntry %}
    &lt;a href="{{ prevEntry.url }}"&gt;{{ prevEntry.title }}&lt;/a&gt;
{% endif %}

{% if nextEntry %}
    &lt;a href="{{ nextEntry.url }}"&gt;{{ nextEntry.title }}&lt;/a&gt;
{% endif %}
</code></pre>

CC BY-SA 3.0
2015-03-31T15:45:53.593Z
2015-03-31T16:21:01.333Z
2015-03-31T16:21:01.333Z
carlcs
<p><strong>On <em>natsort</em>...</strong></p>

<p>When you're sorting a list of entries, the items being sorted are EntryModel <em>objects</em>. The <code>natsort</code> filter won't be very helpful in that case, because <code>natsort</code> is expecting <em>string</em> inputs.</p>

<p>Instead you can use the <code>natsortAs</code> filter as described in the <a href="http://michaelrog.com/craft/lagniappe/supersort" rel="nofollow">Scraper docs</a>:</p>

<pre><code>{% entries | supersort('natsortAs', '{someStringField}') %}
</code></pre>

<p>This way, SuperSort knows exactly which value to sort by, and your results will be consistent.</p>

<p><strong>On <em>getPrev()</em> and <em>getNext()</em>...</strong></p>

<p>The <a href="http://buildwithcraft.com/docs/templating/entrymodel#getPrev" rel="nofollow"><code>getPrev()</code></a> and <a href="http://buildwithcraft.com/docs/templating/entrymodel#getNext" rel="nofollow"><code>getNext()</code></a> methods on an EntryModel relate to its order within a specific ElementCriteriaModel, based on the parameters you provided when you fetched the entries.</p>

<p>If you want to get the "previous" or "next" item in a sorted array, you can utilize Twig's <a href="http://twig.sensiolabs.org/doc/tags/for.html#the-loop-variable" rel="nofollow"><code>loop</code> variable</a>.</p>

<p><code>loop.first</code> and <code>loop.last</code> tell you whether you're at the beginning or end of the loop, and <code>loop.index0 + 1</code> and <code>loop.index0 - 1</code> will refer to the indexes of the next and previous items in the loop.</p>

<p>(c.f. <a href="http://twig.sensiolabs.org/doc/tags/for.html" rel="nofollow">http://twig.sensiolabs.org/doc/tags/for.html</a>)</p>

CC BY-SA 3.0
2015-03-31T15:54:32.993Z
2015-03-31T16:05:49.993Z
2015-03-31T16:05:49.993Z
Michael Rog
<p>I applied the superSort plugin function to a list of entries and it works perfectly:</p>

<pre><code>{% set entries = craft.entries.section('sectionName').type('entryType').order('entryTitle')|supersort('natsort') %}
</code></pre>

<p>Trying to apply it to an entry page with this code to get the previous and next entry. It does not work:</p>

<pre><code>{% set arrowParams = craft.entries.section('sectionName').type('entryType').order('entryTitle')|supersort ('natsort') %}
{% set prevEntry = entry.getPrev(arrowParams) %}{% set nextEntry = entry.getNext(arrowParams) %}
  {% if prevEntry %}
    &lt;a href="{{ prevEntry.url }}"&gt;{{ prevEntry.title }}&lt;/a&gt;
  {% endif %}

  {% if nextEntry %}
    &lt;a href="{{ nextEntry.url }}"&gt;{{ nextEntry.title }}&lt;/a&gt;
  {% endif %}
</code></pre>

<p>Thanks for helping!</p>

<templating><sorting><plugin-supersort>
Using `getPrev` and `getNext` with entries sorted by SuperSort plugin?
# Using `getPrev` and `getNext` with entries sorted by SuperSort plugin?

(Asked by: username_0 on 2015-03-31)

I applied the superSort plugin function to a list of entries and it works perfectly:
{% set entries = craft.entries.section('sectionName').type('entryType').order('entryTitle')|supersort('natsort') %}

Trying to apply it to an entry page with this code to get the previous and next entry. It does not work:
{% set arrowParams = craft.entries.section('sectionName').type('entryType').order('entryTitle')|supersort ('natsort') %}
{% set prevEntry = entry.getPrev(arrowParams) %}{% set nextEntry = entry.getNext(arrowParams) %}
  {% if prevEntry %}
    {{ prevEntry.title }}
  {% endif %}

  {% if nextEntry %}
    {{ nextEntry.title }}
  {% endif %}

Thanks for helping!

**Tags:** templating, sorting, plugin-supersort


---

## 2 answers

### Answer by username_1 on 2015-03-31. Score: 3 | Accepted answer

It won't work with getPrev and getNext, as they only work with ElementCriteriaModels and not with an array of Entry models.
But that is what you get returned from the plugin. Supersort converts your craft.entries ElementCriteriaModel into an array of Entry models. This is necessary so that it can do the sorting.
The only workaround I know of would be to get the IDs of your supersorted entries and pass them to the ID param of a new ElementCriteriaModel.
{% set entries = craft.entries.section('sectionName').type('entryType') %}
{% set entriesSorted = entries|supersort('natsortAs', '{title}') %}

{% set entryIds = [] %}
{% for entry in entriesSorted %}
    {% set entryIds = entryIds|merge([entry.id]) %}
{% endfor %}

{% set arrowCriteria = craft.entries.id(entryIds).fixedOrder(true) %}

Now you have an ElementCriteriaModel arrowCriteria, prepared to get entries in the desired sort order. So now you can use arrowCriteria with your entry methods.
{% set prevEntry = entry.getPrev(arrowCriteria) %}
{% set nextEntry = entry.getNext(arrowCriteria) %}

{% if prevEntry %}
    {{ prevEntry.title }}
{% endif %}

{% if nextEntry %}
    {{ nextEntry.title }}
{% endif %}


---

### Answer by username_2 on 2015-03-31. Score: 2

On natsort...
When you're sorting a list of entries, the items being sorted are EntryModel objects. The natsort filter won't be very helpful in that case, because natsort is expecting string inputs.
Instead you can use the natsortAs filter as described in the Scraper docs:
{% entries | supersort('natsortAs', '{someStringField}') %}

This way, SuperSort knows exactly which value to sort by, and your results will be consistent.
On getPrev() and getNext()...
The getPrev() and getNext() methods on an EntryModel relate to its order within a specific ElementCriteriaModel, based on the parameters you provided when you fetched the entries.
If you want to get the "previous" or "next" item in a sorted array, you can utilize Twig's loop variable.
loop.first and loop.last tell you whether you're at the beginning or end of the loop, and loop.index0 + 1 and loop.index0 - 1 will refer to the indexes of the next and previous items in the loop.
(c.f. http://twig.sensiolabs.org/doc/tags/for.html)


---

