8

How do you output the all the children of a structure in a reverse order (assuming the children are limited to max depth).

Using the order parameter, Craft requires that you use a second parameter like "desc" after a primary order parameter (eg, "title"). This would look like:

craft.entries.section('volumes').order('title desc')

But what would be the primary parameter that would respect the natural structure order?

Or is there any other way?

11

The primary parameter you're looking for is lft:

craft.entries.section('volumes').order('lft desc')
  • Thanks carlcs. Very useful. Handy that the Craft documentation fails to mention that parameter! – bravokiloecho Oct 9 '14 at 9:09
8

You could try using use the reverse twig filter.

{% for entry in craft.entries.section('volumes')|reverse %}
...
{% endfor %}
  • Wouldn't this just reverse the default order, which is 'postDate desc'? – carlcs Oct 8 '14 at 17:17
  • IGNORE my comment. If it's a structure, the default order is in fact the sort order of the entries in the CP. Just tried the reverse filter and it works as you said. – carlcs Oct 8 '14 at 17:26
  • Thanks so much for your help. This should also be the answer but because carlcs's answer addresses the first method of solving the problem, I thought it more suitable to tick that one. – bravokiloecho Oct 9 '14 at 9:08
  • No worries. I like his answer also. I learned something new! ;) – Douglas McDonald Oct 9 '14 at 14:59

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.