Answers.Body: <p>The way to do this is with the <a href="https://craftcms.com/docs/templating/filters#group" rel="nofollow noreferrer">group</a> filter. You want to group the entries by the first character of the title.</p>
  
  <p>Get the entries as an actual array</p>
  
  <pre><code>{% set allEntries = craft.entries.section('artists').order('title').find %}
  </code></pre>
  
  <p>Group them by first letter of title. <a href="https://twig.symfony.com/doc/2.x/filters/first.html" rel="nofollow noreferrer">first</a> will return the first character of a string. <a href="https://twig.symfony.com/doc/2.x/filters/upper.html" rel="nofollow noreferrer">upper</a> converts a string to uppercase.</p>
  
  <pre><code>{% set groupedEntries = allEntries|group('title|first|upper') %}
  </code></pre>
  
  <p>Now you can loop through them:</p>
  
  <pre><code>{% for index, values in groupedEntries %}
    &lt;h2&gt;{{index}}&lt;/h2&gt;
    &lt;ul class="sub-nav"&gt;
      {% for e in values %}
        &lt;li&gt;...{{e}}...&lt;/li&gt;
      {% endfor %}
    &lt;/ul&gt;
  {% endfor %}
  </code></pre>
  
  <p>See also <a href="https://craftcms.stackexchange.com/questions/5404/how-can-i-group-a-list-of-tags-into-ranges-of-first-letters-a-e-f-j-etc">this question</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-16T13:30:11.280Z
Answers.Text: Thanks! Edited that slightly to:
  {% set entriesGrouped = allEntries|group('title|slice(0, 1)|upper|replace("/[^A-Z]/", "0-9")') %}
  to get 0-9 rather then 0,1,2 etc.
Answers.UserDisplayName: sarah3585
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-10-16T12:57:10.367Z
Answers.LastActivityDate: 2017-10-16T12:57:10.367Z
Answers.UserDisplayName: Marion Newlevant
Body: <p>I'm created an Index like page (like at the back of a book) for entries within a certain section, ordered alphabetically with the letter proceeding it.</p>
  
  <p>My code below seems like a tedious way to do it, is their an easier way? </p>
  
  <p>How would I handle the entries with a number as the first character (0-9) of the title?</p>
  
  <pre><code>     &lt;h2&gt;A&lt;/h2&gt;
  
       &lt;ul class="sub-nav"&gt;
        {% for entry in craft.entries.section('artists').search('title::A*').order('title').find() %}
          &lt;li&gt;...&lt;/li&gt;
          {% endfor %}
        &lt;/ul&gt;
  
      &lt;h2&gt;B&lt;/h2&gt;
  
       &lt;ul class="sub-nav"&gt;
        {% for entry in craft.entries.section('artists').search('title::B*').order('title').find() %}
          &lt;li&gt;...&lt;/li&gt;
          {% endfor %}
        &lt;/ul&gt;
  
  
      &lt;h2&gt;C&lt;/h2&gt;
  
       &lt;ul class="sub-nav"&gt;
        {% for entry in craft.entries.section('artists').search('title::C*').order('title').find() %}
          &lt;li&gt;...&lt;/li&gt;
          {% endfor %}
        &lt;/ul&gt;
  </code></pre>
  
Tags: <templating><navigation><order>
Title: Creating a sitemap/index page, ordered by A-Z and 0-9
ThreadText: # Creating a sitemap/index page, ordered by A-Z and 0-9
  
  (Asked by: username_0 on 2017-10-16)
  
  I'm created an Index like page (like at the back of a book) for entries within a certain section, ordered alphabetically with the letter proceeding it.
  
  My code below seems like a tedious way to do it, is their an easier way?
  
  How would I handle the entries with a number as the first character (0-9) of the title?
  
  ```
       <h2>A</h2>
  
       <ul class="sub-nav">
        {% for entry in craft.entries.section('artists').search('title::A*').order('title').find() %}
          <li>...</li>
          {% endfor %}
        </ul>
  
      <h2>B</h2>
  
       <ul class="sub-nav">
        {% for entry in craft.entries.section('artists').search('title::B*').order('title').find() %}
          <li>...</li>
          {% endfor %}
        </ul>
  
      <h2>C</h2>
  
       <ul class="sub-nav">
        {% for entry in craft.entries.section('artists').search('title::C*').order('title').find() %}
          <li>...</li>
          {% endfor %}
        </ul>
  
  ```
  
  **Tags:** templating, navigation, order
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2017-10-16. Score: 4 | Accepted answer
  
  The way to do this is with the [group](https://craftcms.com/docs/templating/filters#group) filter. You want to group the entries by the first character of the title.
  
  Get the entries as an actual array
  
  ```
  {% set allEntries = craft.entries.section('artists').order('title').find %}
  
  ```
  
  Group them by first letter of title. [first](https://twig.symfony.com/doc/2.x/filters/first.html) will return the first character of a string. [upper](https://twig.symfony.com/doc/2.x/filters/upper.html) converts a string to uppercase.
  
  ```
  {% set groupedEntries = allEntries|group('title|first|upper') %}
  
  ```
  
  Now you can loop through them:
  
  ```
  {% for index, values in groupedEntries %}
    <h2>{{index}}</h2>
    <ul class="sub-nav">
      {% for e in values %}
        <li>...{{e}}...</li>
      {% endfor %}
    </ul>
  {% endfor %}
  
  ```
  
  See also [this question](https://craftcms.stackexchange.com/questions/5404/how-can-i-group-a-list-of-tags-into-ranges-of-first-letters-a-e-f-j-etc).
  
  > **Comments:**
  > **username_0**: Thanks! Edited that slightly to: {% set entriesGrouped = allEntries|group('title|slice(0, 1)|upper|replace("/[^A-Z]/", "0-9")') %} to get 0-9 rather then 0,1,2 etc.  
  
  ---
  
  