Answers.Body: <p>I'd suggest breaking your problem down into code which gathers the IDs of each of the types of entries first, then outputs them....roughly like this (very much untested!! - but should be enough to understand the approach):</p>
  
  <pre><code>{# Arrays to store the IDs of the entries as we find them #}
  {% set noDateIDs = [] %}
  {% set dateIDs = [] %}
  
  {% for entry in craft.entries.section('heroes').order('date') %}
  
      {% if entry.date|length %}
          {% set dateIDs = dateIDs|merge([entry.id])} %}
          {# Or of course you could output the data you want here directly but I like to keep my building and output separate for clarity #}
      {% else %}
          {% set noDateIDs = noDateIDs|merge([entry.id])}  %}
      {% endif %}
  
  {% endfor %}
  
  {% set noDateIDsString = noDateIDs|join(', ') %}
  {% set dateIDsString = dateIDs|join(', ')  %}
  
  {# Now actually output the dated entries #}
  {% for entry in craft.entries.section('heroes').id(noDateIDsString).find() %}
  
      &lt;article&gt;
          &lt;h3&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt; - {{ entry.date|date("j") }}{{ entry.date|date("S") }} {{ entry.date|date("F") }} {{ entry.date|date("Y")}} - {% for category in entry.genre %}{{ category.title }}{% endfor %}&lt;/h3&gt;
      &lt;/article&gt;
  
  {% endfor %}
  
  {# Output the undated ones ordered by postDate #}
  {% for entry in craft.entries.section('heroes').id(dateIDsString).order('postDate') %}
  
          &lt;article&gt;
              &lt;h3&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h3&gt;
          &lt;/article&gt;
  
  {% endfor %}
  </code></pre>
  
  <p>This approach is very useful generally in Craft, and is documented really well <a href="http://webstoemp.com/blog/manipulating-craft-elementcriteriamodel-with-twig/?utm_campaign=Craft%2BLink%2BList&amp;utm_medium=email&amp;utm_source=Craft_Link_List_10" rel="nofollow">here</a> in 'Manipulating Craft's ElementCriteriaModel objects with Twig' by Jérôme Coupé of Webstoemp </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-28T05:04:12.767Z
Answers.Text: You *can* probably pass  the ids directly as an array rather than doing that string conversion, not sure on that...
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-28T07:00:37.283Z
Answers.Text: Apologies, I rephrased my question. Your answer is great for weeding out the ones without dates but I still need to loop through the categories, first and foremost.
Answers.UserDisplayName: MikeeBee
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-29T01:27:26.340Z
Answers.Text: Just to finish off our slack convo it's easy to loop over categories.  Within you could e.g. loop dates and get the 1st entry for that cat on that date. I still don't think that's quite what you want - the better approach would be list all the events that are under a category by date, or  list events on a date by ctaegory.  Looping both categories and dates is tricky & I am not even convinced the output would make much sense from a presentation point of view so I'd advise talking to the client more and showing them more real world examples of where this might not make much sense.  Just my 2c!
Answers.UserDisplayName: Jeremy Daalder
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-29T06:05:16.763Z
Answers.Text: Agreed. The output will make no sense and be unhelpful to the user. I'm pushing back to the client in the hope that they see sense! Still might have to do it though :/
Answers.UserDisplayName: MikeeBee
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-02-28T04:52:51.203Z
Answers.LastActivityDate: 2016-02-28T05:00:24.923Z
Answers.LastEditDate: 2016-02-28T05:00:24.923Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>I have a channel with entries that may or may not have a custom date field populated.</p>
  
  <p>I'd like the display a list of entries, looping through each category, showing one entry from each category. Then just start the loop again.</p>
  
  <p>Then, show the rest of the entries which <strong>don't</strong> have the date field populated. I guess they would just have to be just ordered by postDate, but still only showing one per category each loop.</p>
  
  <p>So (assuming there are 3 categories in total)...</p>
  
  <ol>
  <li>Entry - 4th April - Category 1</li>
  <li>Entry - 6th April - Category 2</li>
  <li>Entry - 8th April - Category 3</li>
  <li>Entry - 5th April - Category 1 - <em>start the loop through categories again</em></li>
  <li>Entry - 7th April - Category 2</li>
  <li>Entry - 9th April - Category 3</li>
  <li>Entry - Category 1</li>
  <li>Entry - Category 2</li>
  <li>Entry - Category 3</li>
  </ol>
  
  <p><strong>Note that the dates appear jumbled</strong>, as the categories are the thing dictating the order. Date order is a factor, but secondary to the looping of the categories.</p>
  
  <p>This is the code I have so far, all it does is output the entries but with the ones without date fields populated appearing first.</p>
  
  <pre><code>{% for entry in craft.entries.section('heroes').order('date') %}
  
      {% if entry.date|length %}
  
          &lt;article&gt;
              &lt;h3&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt; - {{ entry.date|date("j") }}{{ entry.date|date("S") }} {{ entry.date|date("F") }} {{ entry.date|date("Y")}} - {% for category in entry.genre %}{{ category.title }}{% endfor %}&lt;/h3&gt;
          &lt;/article&gt;
  
      {% else %}
  
          &lt;article&gt;
              &lt;h3&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h3&gt;
          &lt;/article&gt;
  
      {% endif %}
  
  {% endfor %}
  </code></pre>
  
  <p>Hope that makes sense! Any help will be appreciated.</p>
  
Tags: <entries><categories><ordering>
Title: Loop through entries with custom ordering, showing one from each category then start loop again
ThreadText: # Loop through entries with custom ordering, showing one from each category then start loop again
  
  (Asked by: username_0 on 2016-02-28)
  
  I have a channel with entries that may or may not have a custom date field populated.
  
  I'd like the display a list of entries, looping through each category, showing one entry from each category. Then just start the loop again.
  
  Then, show the rest of the entries which **don't** have the date field populated. I guess they would just have to be just ordered by postDate, but still only showing one per category each loop.
  
  So (assuming there are 3 categories in total)...
  
  1. Entry - 4th April - Category 1
  2. Entry - 6th April - Category 2
  3. Entry - 8th April - Category 3
  4. Entry - 5th April - Category 1 - *start the loop through categories again*
  5. Entry - 7th April - Category 2
  6. Entry - 9th April - Category 3
  7. Entry - Category 1
  8. Entry - Category 2
  9. Entry - Category 3
  
  **Note that the dates appear jumbled**, as the categories are the thing dictating the order. Date order is a factor, but secondary to the looping of the categories.
  
  This is the code I have so far, all it does is output the entries but with the ones without date fields populated appearing first.
  
  ```
  {% for entry in craft.entries.section('heroes').order('date') %}
  
      {% if entry.date|length %}
  
          <article>
              <h3><a href="{{ entry.url }}">{{ entry.title }}</a> - {{ entry.date|date("j") }}{{ entry.date|date("S") }} {{ entry.date|date("F") }} {{ entry.date|date("Y")}} - {% for category in entry.genre %}{{ category.title }}{% endfor %}</h3>
          </article>
  
      {% else %}
  
          <article>
              <h3><a href="{{ entry.url }}">{{ entry.title }}</a></h3>
          </article>
  
      {% endif %}
  
  {% endfor %}
  
  ```
  
  Hope that makes sense! Any help will be appreciated.
  
  **Tags:** entries, categories, ordering
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2016-02-28. Score: 3
  
  I'd suggest breaking your problem down into code which gathers the IDs of each of the types of entries first, then outputs them....roughly like this (very much untested!! - but should be enough to understand the approach):
  
  ```
  {# Arrays to store the IDs of the entries as we find them #}
  {% set noDateIDs = [] %}
  {% set dateIDs = [] %}
  
  {% for entry in craft.entries.section('heroes').order('date') %}
  
      {% if entry.date|length %}
          {% set dateIDs = dateIDs|merge([entry.id])} %}
          {# Or of course you could output the data you want here directly but I like to keep my building and output separate for clarity #}
      {% else %}
          {% set noDateIDs = noDateIDs|merge([entry.id])}  %}
      {% endif %}
  
  {% endfor %}
  
  {% set noDateIDsString = noDateIDs|join(', ') %}
  {% set dateIDsString = dateIDs|join(', ')  %}
  
  {# Now actually output the dated entries #}
  {% for entry in craft.entries.section('heroes').id(noDateIDsString).find() %}
  
      <article>
          <h3><a href="{{ entry.url }}">{{ entry.title }}</a> - {{ entry.date|date("j") }}{{ entry.date|date("S") }} {{ entry.date|date("F") }} {{ entry.date|date("Y")}} - {% for category in entry.genre %}{{ category.title }}{% endfor %}</h3>
      </article>
  
  {% endfor %}
  
  {# Output the undated ones ordered by postDate #}
  {% for entry in craft.entries.section('heroes').id(dateIDsString).order('postDate') %}
  
          <article>
              <h3><a href="{{ entry.url }}">{{ entry.title }}</a></h3>
          </article>
  
  {% endfor %}
  
  ```
  
  This approach is very useful generally in Craft, and is documented really well [here](http://webstoemp.com/blog/manipulating-craft-elementcriteriamodel-with-twig/?utm_campaign=Craft%2BLink%2BList&utm_medium=email&utm_source=Craft_Link_List_10) in 'Manipulating Craft's ElementCriteriaModel objects with Twig' by Jérôme Coupé of Webstoemp
  
  > **Comments:**
  > **username_1**: You *can* probably pass  the ids directly as an array rather than doing that string conversion, not sure on that...  
  > **username_0**: Apologies, I rephrased my question. Your answer is great for weeding out the ones without dates but I still need to loop through the categories, first and foremost.  
  > **username_1**: Just to finish off our slack convo it's easy to loop over categories.  Within you could e.g. loop dates and get the 1st entry for that cat on that date. I still don't think that's quite what you want - the better approach would be list all the events that are under a category by date, or  list events on a date by ctaegory.  Looping both categories and dates is tricky & I am not even convinced the output would make much sense from a presentation point of view so I'd advise talking to the client more and showing them more real world examples of where this might not make much sense.  Just my 2c!  
  > **username_0**: Agreed. The output will make no sense and be unhelpful to the user. I'm pushing back to the client in the hope that they see sense! Still might have to do it though :/  
  
  ---
  
  