2

Not sure if what I am looking is possible, but basically I have a section ('portfolio'). At the bottom of each entry I have links to the previous and next entry. Simple.

My trouble is that the body field in my entries is not always populated, and because of this I would like to by-pass these ones in my nav at the bottom of an entry page.

See my code below which is not working, I have a feeling that my logic is not going in the right direction at all with this...

{% set params = craft.entries.section('portfolio') %}

{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}

{% if prevEntry and prevEntry.body | length %}
    {% set image = prevEntry.portfolioImages.first() %}
    <a href="{{ prevEntry.url }}">Previous</a>
{% endif %}

{% if nextEntry and nextEntry.body | length %}
    {% set image = nextEntry.portfolioImages.first() %}
    <a href="{{ nextEntry.url }}">Next</a>
{% endif %}

1 Answer 1

2

You can add the "non-empty body" conditional to your parameters, as follows:

{% set params = craft.entries.section('portfolio').body(':notempty:') %}
{% set previousEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}
{# …and so forth #}
0

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.