2

So I'm trying to loop through some entries and order them by in a specific way. For an example let's say I have the following entires:

  • Example01
  • Example02
  • Example03
  • Example04

I now want to loop through these entries and order them in an order such as: Example03, Example01, Example04 and Example2. The order has to be custom where I can change it.

Is this possible and if so how can I achieve this? Thanks

1 Answer 1

2

You have a few options here:

  • Use an Entries field (as a Global or as a fields on a Single maybe?) to chose the entries and order them
  • Make the Entries a Structure section, so you can set the order
  • use craft.entries({ ids: [3, 1, 2], fixedOrder: true }) and query the Entries by ID (if they'll never be deleted and you're cool with hard-coding the order)
  • create an order field on that entry type to query them by, also with craft.entries()

It's up to you what the best solution would be, given your set-up, but you have plenty of options.

1
  • Is there a means of hard-coding order in templates using slug rather than ID? At the moment I have multiple for loops with if conditions, each matching a slug. Commented Feb 22, 2018 at 14:52

Your Answer

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

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