I have two sections:

Games has a field called 'GamesPublisher' that is Entries type (set to Publishers)

I have a publisher called 'Microsoft' with an ID of 49.

I want to display all Game entries for the Publisher 'Microsoft' (ie ID 49)

I also want to set the order of the displaying in ASC order based on the field 'GamesCatalogNumber' which is in the section Games.

So far, it looks OK, but I have yet to figure out to limit entries to a specific Publisher. http://www.colorcomputergames.com/tandy-catalog/

{% set entries = craft.entries.section('games').relatedTo(entry) %}
    {% for entry in entries.order('GamesCatalogNumber desc') %}
     <li>{{ entry.GamesCatalogNumber }}: <a href="{{ entry.url }}">{{ entry.title }}</a></li>
    {% endfor %}

    {# Set parameters for prev/next elements list #}
    {% set params = craft.entries.section('publishers').order('title asc') %}

    {# Get the prev/next elements #}
    {% set prevEntry = entry.getPrev(params) %}
    {% set nextEntry = entry.getNext(params) %}

    {# And make sure to only output the links if the element exists #}
    {% if prevEntry %}<a href="{{ prevEntry.url }}">Previous Publisher</a>{% endif %}
    {% if nextEntry %}<a href="{{ nextEntry.url }}">Next Publisher</a>{% endif %}
  • 1
    I have the above somewhat working, but I don't think my solution is efficient. As only the publisher 'Microsoft' (ID:49) will every have data in the field GamesCatalogNumber, I put an IF statement to only display the <li> if that field is not empty. Oddly, it works when the FOR loop is set to order in DESC order but fails in ASC order. colorcomputergames.com/tandy-catalog/test.html
    – DevServe
    Dec 27, 2016 at 3:57
  • 1
    What field type is GamesCatalogNumber ? Dec 27, 2016 at 12:07
  • @AndréElvan, GamesCatalogNumber is just a TEXT field.
    – DevServe
    Dec 29, 2016 at 1:41
  • Regarding the problem with the sorting, if the field is text, it will be sorted as a text string, even if the value is a number, so this will not make any sense. Try changing it to a Number field. Dec 29, 2016 at 14:25

1 Answer 1


Looks to me like your solution is mostly correct, except for handling the gamesCatalogNumber. For that you could either:

  • test for specific publisher(s) by id or slug
  • test if gamesCatalogNumber is empty on the first entry (and assume that the publisher doesn't use catalog numbers), or
  • (recommended solution) add a checkbox or lightSwitch field to the publisher called 'usesCatalogNumbers' and test for that.

Something like:

{# publisher template #}

{% if entry.usesCatalogNumbers %}
    {% set games = craft.entries.section('games').relatedTo(entry).order('gamesCatalogNumber desc') %}
{% else %}
    {% set games = craft.entries.section('games').relatedTo(entry).order('title asc') %}
{% endif %}

    {% for game in games %}
        <li>{% if entry.usesCatalogNumbers %}{{ entry.gamesCatalogNumber }}: {% endif %}<a href="{{ entry.url }}">{{ entry.title }}</a></li>
    {% endfor %}

{% set params = craft.entries.section('publishers').order('title asc') %}
{% set prevEntry = entry.getPrev(params) %}
{% set nextEntry = entry.getNext(params) %}
{% if prevEntry %}<a href="{{ prevEntry.url }}">Previous Publisher</a> {% endif %}{% if nextEntry %}<a href="{{ nextEntry.url }}">Next Publisher</a>{% endif %}

I recommend this (instead of the other options) because it's a bit more explicit and extensible (i.e. allows you to add other publishers that use catalog numbers without modifying the templates).

  • Revisiting this... Setting aside the Publisher section aspect of the original post. I think I just want to list out all games that contains 'something' (not null) in the field GamesCatalogNumber. Running into problems also getting it to work with pagination. :-(
    – DevServe
    Dec 29, 2016 at 1:44

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.