9

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?

2 Answers 2

13

The primary parameter you're looking for is lft:

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

You could try using use the reverse twig filter.

{% for entry in craft.entries.section('volumes')|reverse %}
...
{% endfor %}
4
  • Wouldn't this just reverse the default order, which is 'postDate desc'?
    – carlcs
    Oct 8, 2014 at 17:17
  • 1
    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, 2014 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. Oct 9, 2014 at 9:08
  • No worries. I like his answer also. I learned something new! ;) Oct 9, 2014 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.