The natural sort order for related entries is the order defined in the control panel (not the post date of the related entries), unless you otherwise specify the sort order. Here is an example taken from one of my projects, where related articles are defined within an entries field-type in an article entry:
{% set relatedArticles = entry.relatedArticles %}
<ul>
{% for article in relatedArticles %}
<li><a href="{{ article.url }}">{{ article.title }}</a></li>
{% endfor %}
</ul>
On the backend, craft uses the table craft_relations
to create the relationship with the columns sourceId
, targetId
, and sortOrder
. This sortOrder
column defines the default sort order when accessing related entries through the related 'entries' field-type.
If on the other hand, you are accessing related entries using the .relatedTo()
method of the EntryCriteriaModel then you will need to specify the sort order using .order('sortOrder')
.
Update
Here is the original code:
{% set relatedRecords = craft.entries.section('contenuDiscographie').relatedTo(entry) %}
{% for record in relatedRecords %}
<a href="{{ record.url }}">{{ record.title }}</a>
{% for block in record.discoArtistes %}
{% set relatedPerformers = craft.entries.section('interpretes').relatedTo(block) %}
{% for performer in relatedPerformers %}
{{ performer.title }}
{% endfor %}
{% endfor %}
{% endfor %}
Try using the actual relationship field:
{% set relatedRecords = entry.myRelatedEntriesFieldHandle %}
{% for record in relatedRecords %}
<a href="{{ record.url }}">{{ record.title }}</a>
{% for block in record.myMatrixBlockFieldHandle %}
{% set relatedPerformers = block.myRelatedEntriesFieldHandleInsideMatrixField %}
{% for performer in relatedPerformers %}
{{ performer.title }}
{% endfor %}
{% endfor %}
{% endfor %}
Edit I edited the code above to be more generic, rather than trying to guess what the field handles are named in your project. You need to change these to your actual field handles. From the picture above I would guess they might be 'entry.relatedRecords', 'record.discoArtistes', and 'block.nom' for example.
{% set relatedRecords = craft.entries.section('contenuDiscographie').relatedTo(entry) %} {% for record in relatedRecords %} <a href="{{ record.url }}">{{ record.title }}</a> {% for block in record.discoArtistes %} {% set relatedPerformers = craft.entries.section('interpretes').relatedTo(block) %} {% for performer in relatedPerformers %} // this needs to be sorted // {{ performer.title }} {% endfor %} {% endfor %} {% endfor %} {% endif %}