1

Below is my paginate code. How can I check if there is more than one page? At the moment when there is only one I'm getting a '1' appear at the bottom (the page number) which looks odd. Ideally I only want it to show the pagination if the number of entries exceeds the limit, so only if it needs to display a link to the next page.

{% paginate craft.entries.section('insights').limit(1) as entriesOnPage %}
    {% for entry in entriesOnPage %}
    <article>
        {% for image in entry.blogImage %}
        <img src="{{ image.getUrl()}}" alt="{{ image.title }}" class="gutter-bottom--half"/>
        {% endfor %}
        <h3><a class="descrete-link" href="{{ entry.url }}">{{ entry.title }}</a></h3>
        {{ entry.body|hacksaw(chars='300', append='...') }}
        <br>
        <br>            
        <p><a class="button button--blue gutter-bottom--half" href="{{ entry.url }}">Continue reading</a></p>
        <div class="col-12-nf gutter-bottom">
            <hr>
        </div>
    </article>
    <br>
{% endfor %}

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

{% for page, url in paginate.getPrevUrls(5) %}
    <a href="{{ url }}">{{ page }}</a>
{% endfor %}

<span class="current">{{ paginate.currentPage }}</span>


{% for page, url in paginate.getNextUrls(5) %}
    <a href="{{ url }}">{{ page }}</a>
{% endfor %}

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


{% endpaginate %}
9

The paginate.totalPages variable will give you the total number of pages that are generated by the paginate tag. So you can wrap your display of pages around a conditional that checks to see if this is greater than 1.

{% if paginate.totalPages > 1 %}

    {# output current pages and pagination navigation here #}

{% endif %}

More details, including a full list of variables available, can be found in the pagination docs.

2

The above doesn't display any paging even when there is paging. It needs to be pageInfo not paginate:

{% if pageInfo.totalPages > 1 %}

    {# output current pages and pagination navigation here #}

{% endif %}

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.