2

I have this supersimple navigation:

<ul>
   {% for entry in craft.entries.section('homepage, arbeiten, info, kontakt, shop') %}
       <li>
         <a href="{{ entry.url }}">{{ entry.title }}</a>
        </li>
    {% endfor %}
</ul>

Is it possible to add an order filter which orders the entry by the order I wrote the entry handles? I tried to apply .fixedOrder but that does nothing.

KSPR
  • 3,786
  • 2
  • 29
  • 52

1 Answers1

2

The fixedOrder parameter makes your entries to be returned in the same order as the IDs you pass to the id parameter. So a simple solution would be to look up the entry IDs of your single section entries and get your entries via their IDs instead of the section handles.

{% set entryIds = [3, 14, 15, 9, 26] %}

{% for entry in craft.entries.id(entryIds).fixedOrder(true) %}
    <li><a href="{{ entry.url }}">{{ entry.title }}</a></li>
{% endfor %}

You can eighter look up the IDs in the database, or probably faster: add {{ entry.id }} to your current nav loop!

Update: If you have a good reason to get them via their handles, use this snippet to get the entry IDs.

{% set sectionHandles = ['arbeiten', 'info', 'kontakt', 'shop'] %}

{% cache globally for 3 years %}
    {% set entryIds = [3] %}
    {% for handle in sectionHandles %}
        {% set entryIds = entryIds|merge([ craft.entries.section(handle).first().id ]) %}
    {% endfor %}
{% endcache %}
carlcs
  • 36,220
  • 5
  • 62
  • 139
  • I used the handles instead of ideas for lazyness reasons. I'll go with id's then. Thank you – KSPR Feb 28 '15 at 16:00