2

So I may be somewhat obtuse here, but I’m trying to discern what I might be doing wrong in this instance. I’m attempting to use a {% paginate %} tag inside my craft.entries loop to return a simple next/previous set of pagination links. I have ensured I have two entries already, so I should be seeing the pagination links, correct?

{% for entry in craft.entries.section('houseRules').limit(1) %}
    <div class="rule-content">
        <article>
            {# Content is Here #}
        </article>
    </div>
    {% paginate craft.entries as entries %}
        {% if paginate.prevUrl %}<a href="{{ paginate.prevUrl }}">Previous Page</a>{% endif %}
        {% if paginate.nextUrl %}<a href="{{ paginate.nextUrl }}">Next Page</a>{% endif %}
    {% endpaginate %}
{% endfor %}
3
  • Is this meant to be on a single-entry page? And you just want to show Previous/Next links to the neighboring entries within this “House Rules” section? Jul 15 '14 at 18:07
  • No, sorry. I meant to say this was the index page. I just don’t have anything but a single entry on it at the moment, so I created a dummy entry to test against a limit of (1). Jul 15 '14 at 18:16
  • Got it, thanks. The limit(1) was throwing me off :) Jul 15 '14 at 18:17
5

You have your {% for %} and {% paginate %} tags in the reverse order. You need to wrap the loop and the pagination URLs with the {% paginate %} tag pair:

{% paginate craft.entries.section('houseRules').limit(1) as entries %}

    {% for entry in entries %}
        <div class="rule-content">
            <article>
                {# Content is here #}
            </article>
        </div>
    {% endfor %}

    {% if paginate.prevUrl %}<a href="{{ paginate.prevUrl }}">Previous Page</a>{% endif %}
    {% if paginate.nextUrl %}<a href="{{ paginate.nextUrl }}">Next Page</a>{% endif %}

{% endpaginate %}

Notice how we’re actually looping through entries, rather than a new craft.entries call. That entries variable will be an array of the current page’s entries. All we had to do is define what we wanted that variable to be called (e.g. “entries”).

See http://buildwithcraft.com/docs/templating/tags#paginate for more details on what can be done inside the {% paginate %} tag pair.

1
  • Great, thank you. That was tripping me up somewhat. I think it's because I'm still using an ExpressionEngine mentality when approaching pagination. Jul 15 '14 at 18:28

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.