2

Is there a technique for displaying a list of “Next Entries”, which come from the current Channel. The solution I am using at the moment isn’t cutting it…

I’m using an Entry Offset of 1 to display Entries in a sidebar. This works OK if the Entry Detail page the user is looking at happens to be for the most recent Entry, but this quickly breaks down if displaying any other Entry, as the sidebar always displays a list starting at the second most recent Entry.

How would I display the next entries in the sequence, regardless of which Entry detail page the user is on?

Thank you

2 Answers 2

0

How to query for those entries depends on the sort order of your channel, as you probably want the sort order of your Next Entries to be the same as it is for the channel's index page.

For news or blog like entries which are ordered by postDate desc (default) you can make use of the before parameter.

{% set nextEntries = craft.entries.section('news').before(entry.postDate).limit(12) %}
{% for entry in nextEntries %}
    {{ entry.title }}
{% else %}
    No entries found!
{% endfor %}

Another possibility to query for past entries is to use postDate as a parameter (→ allowed syntax for parameter values)

{% set nextEntries = craft.entries.section('news').postDate('< ' ~ entry.postDate).limit(12) %}

For other types of channels, that might be ordered by title or ID, here some more examples:

{% set nextEntries = craft.entries.section('books').title('< ' ~ entry.title).order('title desc').limit(40) %}
{% set nextEntries = craft.entries.section('rum').age('> ' ~ entry.age).order('age').limit(5) %}
{% set nextEntries = shuffle(craft.entries.section('dreams').id('not ' ~ entry.id).limit(7)) %}
5

.getPrev and .getNext sounds like what you're asking for:
http://buildwithcraft.com/docs/templating/entrymodel#isSiblingOf

{% set params = {
    section: 'cocktails',
    order:   'title'
} %}

{% set prevCocktail = entry.getPrev(params) %}
{% set nextCocktail = entry.getNext(params) %}

{% if prevCocktail %}
    <p>Previous: <a href="{{ prevCocktail.url }}">{{ prevCocktail.title }}</a></p>
{% endif %}

{% if nextCocktail %}
    <p>Next: <a href="{{ nextCocktail.url }}">{{ nextCocktail.title }}</a></p>
{% endif %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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