0

I am setting up a photo gallery and below is what I have right now. My problem is when I go the next page /2 it says that entry does not exist. I have routes set up as /gallery/slug/*, and pointing to this template.

Is there a way to paginate images like this?

 {% paginate entry.images.limit(20) as imagesOnPage %}
  {% for image in imagesOnPage %}
    <div class="thumb col-1-4">
        <a href="{{ image.getUrl() }}" data-fresco-group="{{ entry.id }}" data-fresco-caption="{{ image.title }}" title="{{ image.title }}" class="fresco">
                <img src="{{ image.getUrl('galleryThumbnail') }}" title="{{ image.title }}" alt="{{ image.title }}">
          </a>
    </div>
  {% endfor %}

  <div class="pagination">
    {% if paginate.prevUrl %}<a href="{{ paginate.prevUrl }}" class="prev">◄</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 }}" class="page-numbers">{{ page }}</a>
    {% endfor %}

    {% if paginate.nextUrl %}<a href="{{ paginate.nextUrl }}" class="next">►</a>{% endif %}

  </div>
{% endpaginate %}
0

You should actually go to /p2 - this has been a bug in some 2.4 releases, so can you tell me if you are on the latest version?

|improve this answer|||||
  • Yup, you're right, there was one update, and after I ran that it started working. before the update the links were pointing to /2 and now with build 2.4.2669 they point to /p2. Thanks! – Kenyon Kowal Jun 13 '15 at 3:20
1

The {% paginate %} tag requires the ElementCriteriaModel to be passed through first.

Since you were requesting entry.images.limit(20) to be paginated, I suspect you have your images set up within a single images asset. Instead you will need to set up your images within a channel or structure if you would like Craft to paginate the gallery between several pages.

This hasn't been tested, although spot the differences with the inclusion of the craft prefix within the ElementCriteriaModel.

{% paginate craft.entries.section("gallery").limit(20) as imagesOnPage %}

    {% for entry in imagesOnPage %}
        <div class="thumb col-1-4">
<a href="{{ entry.image.getUrl() }}" data-fresco-group="{{ entry.id }}" data-fresco-caption="{{ entry.image.title }}" title="{{ entry.image.title }}" class="fresco">
                <img src="{{ entry.image.getUrl('galleryThumbnail') }}" title="{{ entry.image.title }}" alt="{{ entry.image.title }}">
            </a>
        </div>
    {% endfor %}

  <div class="pagination">
    {% if paginate.prevUrl %}<a href="{{ paginate.prevUrl }}" class="prev">◄</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 }}" class="page-numbers">{{ page }}</a>
    {% endfor %}

    {% if paginate.nextUrl %}<a href="{{ paginate.nextUrl }}" class="next">►</a>{% endif %}

  </div>
{% endpaginate %}`

Sources: http://buildwithcraft.com/docs/templating/paginate, http://buildwithcraft.com/docs/templating/elementcriteriamodel

|improve this answer|||||
  • entry.images.limit(20) is an ElementCriteriaModel just as well – Bob Olde Hampsink Jun 12 '15 at 6:54

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.