I am trying to figure out how to page through only the children of the top level section entry being displayed, I have looked at this question but as I say I am after only the children not the siblings.

Is there a prevChild() and nextChild() or something similar I can't see them in the docs.

Response to Bryan

So I would do something like:

{% set prevDatabyteSeries = entry.getChildren().first().getPrevSibling() %}
{% set nextDatabyteSeries = entry.getChildren().first().getNextSibling() %}

{% if prevDatabyteSeries %}
<a href="{{ prevDatabyteSeries.url }}" class="icon-alone paginate-arrow">
  <i class="icon-arrow-left"></i>
{% endif %}

{% if nextDatabyteSeries %}
<a href="{{ nextDatabyteSeries.url }}" class="icon-alone paginate-arrow">
  <i class="icon-arrow-right"></i>
{% endif %}

getPrev, getNext, getPrevSibling, getNextSibling all specify an entry relative to the current one. prevChild and nextChild if they existed would somehow specify an entry relative to a child of the current entry. They don't exist.

What you can do is paginate through the children. Here I use .limit(1) to page through them one at a time, but you could fetch more.

{% set prePaginatedEntries = entry.getChildren().limit(1) %}
{% paginate prePaginatedEntries as entries %}
  {% for oneChild in entries %}
    {# do whatever with oneChild #}
  {% endfor %}
  {# pagination links #}
  {% if paginate.prevUrl %}
    <a href="{{ paginate.prevUrl }}">Previous Page</a>
  {% endif %}

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

There is no getPrevChild and getNextChild methods, but the getPrevSibling and getNextSibling should still serve your purpose. You would simply call it on the child entry instead of its parent.

Another method would be to gather all the children in one go and paginate them via JavaScript.

And yet another method would be the paginate tag. paginate works using any criteria. When you use getChildren, you are getting criteria that's used to pull the child entries.

{% paginate entry.getChildren().limit(1) as entries %}

As per the docs, you would then get the paginate.prevUrl and paginate.nextUrl variables to page through as needed.

  • Hi Bryan, ref. your first option how would I get the child entry instead of its parent?
    – Gareth
    Jul 17 '14 at 13:42
  • entry.getChildren().first() All references to entries, assets, categories, etc. is just that: references. They don't contain the actual elements, but an ElementCriteriaModel that can pull those elements. In this case, the children of your parent entry. Jul 17 '14 at 13:48
  • Bryan, please see my code update - it doesn't work, sorry I have probably misunderstood.
    – Gareth
    Jul 17 '14 at 13:57
  • It's getNextSibling and getPrevSibling. You forgot the get in the method name. Also, you should think about how your urls will look. This might send you to the sibling's full page which will need to handle the parent differently that how you seem to have in this example. Jul 17 '14 at 14:01
  • entry.getChildren().first().prevSibling() is never going to find anything - you are asking for the one before the first one. Jul 17 '14 at 14:08

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.