<p>How are the entries ordered (by date in a channel, manually in a structure or other?)</p>

<p>Are you using the entries anywhere elsewhere at all?</p>

<p>There are a couple of ways you could go, If the Galleries are related to the Updates, you could create a relationship from one to another using an entries field, and then just have the parent render the child in the same loop to different single page entry templates.</p>

<p>Depending on how the URLs need to be, you could use two different entry types in the same channel or structure.  If you need different URL structure you could always use {type} in the 'Entry URL Format' setting and then use custom routes if needed.</p>

<p>Hope this helps :)</p>

<p>I don't think you need to get as complex with arrays or anything.</p>

CC BY-SA 3.0
2015-06-03T04:10:27.880Z
2015-06-03T04:10:27.880Z
Steve Adams
<p>To list entries of two sections in alternating order, I would do this.</p>

<p>Use the <a href="http://buildwithcraft.com/docs/templating/elementcriteriamodel#ids" rel="nofollow"><code>ids</code></a> method to get an array of entry IDs for both of your sections. Then combine those arrays of IDs by <a href="http://twig.sensiolabs.org/doc/tags/for.html" rel="nofollow">iterating over a sequence '0..x'</a>, and for each step pull one ID from each of the individual arrays with <a href="http://twig.sensiolabs.org/doc/filters/merge.html" rel="nofollow"><code>merge</code></a>. You can now use that array of IDs in a new ElementCriteriaModel to get the entries you're after.</p>

<pre><code>{% set galleryEntriesIds = craft.entries.section('gallery').limit(null).ids() %}
{% set updateEntriesIds = craft.entries.section('update').limit(null).ids() %}

{% set mixedEntriesIds = [] %}

{% for key in 0..50 %}

    {% if galleryEntriesIds[key] is defined %}
        {% set mixedEntriesIds = mixedEntriesIds|merge(galleryEntriesIds[key]) %}
    {% endif %}

    {% if updateEntriesIds[key] is defined %}
        {% set mixedEntriesIds = mixedEntriesIds|merge(updateEntriesIds[key]) %}
    {% endif %}

{% endfor %}

{% set mixedEntries = craft.entries.id(mixedEntriesIds).fixedOrder(true) %}
</code></pre>

<p>Use <a href="http://buildwithcraft.com/docs/templating/entrymodel#getSection" rel="nofollow"><code>getSection</code></a> to check which section an entry belongs to within your loops.</p>

<pre><code>{% paginate mixedEntries as entriesOnPage %}
    {% for entry in entriesOnPage %}

        {% if entry.getSection().handle == 'gallery' %}
            ...
        {% else %}
            ...
        {% endif %}

    {% endfor %}
{% endpaginate %}
</code></pre>

CC BY-SA 3.0
2015-06-04T00:04:39.270Z
2015-06-04T07:19:13.537Z
2015-06-04T07:19:13.537Z
carlcs
<p>On my homepage I have one entry that is constantly there. Below that entry I want to display 2 different types of entries in an alternate order (gallery, update, gallery, update...).</p>

<p>Right now I have it so that I'm getting all the sections, setting it to a variable and looping through doing a entry.type check so it renders according to it's type. What would happen now is that it would display everything according to the posts' time.</p>

<p>Thoughts? Ideas? </p>

<p>Thanks.</p>

<p>my code</p>

<pre><code>{# story #}
 {% for entry in craft.entries.section('stories').limit(1) %}
    &lt;div class="row"&gt;
    &lt;div class="large-6 large-centered columns test"&gt;
    &lt;article&gt;
        &lt;h3&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h3&gt;
        &lt;p&gt;Posted on {{ entry.postDate.format('F d, Y') }}&lt;/p&gt;
        {{ entry.body.getPage(1) }}
        &lt;img src="{{ entry.mainFeaturedImage.first().url }}"&gt;
        &lt;p&gt;&lt;a href="{{ entry.url }}"&gt;Continue reading&lt;/a&gt;&lt;/p&gt;
    &lt;/article&gt;
&lt;/div&gt;
&lt;/div&gt;
{% endfor %}
{# end of story #}

{% set entry3 = craft.sections.getAllSections() %}  
&lt;div id="next-entries"&gt;
{% paginate craft.entries(entry3).limit(2) as entries %}
{% for entry in entries %}
{% if entry.type == 'carousels' %}
        &lt;div class="row"&gt;
            &lt;div class="large-12 large-centered columns"&gt;
                &lt;article&gt;
                    &lt;h3&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h3&gt;
                    &lt;p&gt;Posted on {{ entry.postDate.format('F d, Y') }}&lt;/p&gt;
                    {# {{ entry.body.getPage(1) }} #}
                    &lt;div class="row"&gt;
                        &lt;div class="fade"&gt;
                    {% for block in entry.gallery.limit(3).find() %}
                    {% set asset = block.galleryImage.first() %}
                    {# {% set asset2 = block.galleryImage.nth(2) %} #}
                        &lt;img class="large-4 columns carousel-image" src="{{ asset.url }}"&gt;

                    {% endfor %}
                    &lt;/div&gt;
                &lt;/div&gt;
                    &lt;p&gt;&lt;a href="{{ entry.url }}"&gt;Continue reading&lt;/a&gt;&lt;/p&gt;
                &lt;/article&gt;
            &lt;/div&gt;
        &lt;/div&gt;
{% elseif entry.type == 'updates' %}
        &lt;div class="row"&gt;
            &lt;div class="large-6 large-centered columns"&gt;
                &lt;article&gt;
                    &lt;h3&gt;&lt;a href="{{ entry.url }}"&gt;{{ entry.title }}&lt;/a&gt;&lt;/h3&gt;
                    &lt;p&gt;Posted on {{ entry.postDate.format('F d, Y') }}&lt;/p&gt;
                    {{ entry.body.getPage(1) }}
                    &lt;img src="{{ entry.mainFeaturedImage.first().url }}"&gt;
                    &lt;p&gt;&lt;a href="{{ entry.url }}"&gt;Continue reading&lt;/a&gt;&lt;/p&gt;
                &lt;/article&gt;
            &lt;/div&gt;
        &lt;/div&gt;
{% endif %}

{% endfor %}
{% endpaginate %}
&lt;/div&gt;
</code></pre>

CC BY-SA 3.0
2015-05-31T14:39:43.720Z
Could you post the code to how your currently doing this to avoid a duplicate solution :)
Alec Ritson
CC BY-SA 3.0
2015-06-05T04:17:46.677Z
@fishfillet still problems setting this up?
carlcs
<templating><entries><array><singles>
How to render entries on a singles page in a specific pattern/order?
# How to render entries on a singles page in a specific pattern/order?

(Asked by: username_0 on 2015-05-29)

On my homepage I have one entry that is constantly there. Below that entry I want to display 2 different types of entries in an alternate order (gallery, update, gallery, update...).
Right now I have it so that I'm getting all the sections, setting it to a variable and looping through doing a entry.type check so it renders according to it's type. What would happen now is that it would display everything according to the posts' time.
Thoughts? Ideas? 
Thanks.
my code
{# story #}
 {% for entry in craft.entries.section('stories').limit(1) %}
    
    
    
        {{ entry.title }}
        Posted on {{ entry.postDate.format('F d, Y') }}
        {{ entry.body.getPage(1) }}
        
        Continue reading
    


{% endfor %}
{# end of story #}

{% set entry3 = craft.sections.getAllSections() %}  

{% paginate craft.entries(entry3).limit(2) as entries %}
{% for entry in entries %}
{% if entry.type == 'carousels' %}
        
            
                
                    {{ entry.title }}
                    Posted on {{ entry.postDate.format('F d, Y') }}
                    {# {{ entry.body.getPage(1) }} #}
                    
                        
                    {% for block in entry.gallery.limit(3).find() %}
                    {% set asset = block.galleryImage.first() %}
                    {# {% set asset2 = block.galleryImage.nth(2) %} #}
                        

                    {% endfor %}
                    
                
                    Continue reading
                
            
        
{% elseif entry.type == 'updates' %}
        
            
                
                    {{ entry.title }}
                    Posted on {{ entry.postDate.format('F d, Y') }}
                    {{ entry.body.getPage(1) }}
                    
                    Continue reading
                
            
        
{% endif %}

{% endfor %}
{% endpaginate %}

**Tags:** templating, entries, array, singles

> **Comments:**
> **username_1**: Could you post the code to how your currently doing this to avoid a duplicate solution :)  
> **username_2**: @username_0 still problems setting this up?  

---

## 2 answers

### Answer by username_3 on 2015-06-03. Score: 1

How are the entries ordered (by date in a channel, manually in a structure or other?)

Are you using the entries anywhere elsewhere at all?

There are a couple of ways you could go, If the Galleries are related to the Updates, you could create a relationship from one to another using an entries field, and then just have the parent render the child in the same loop to different single page entry templates.

Depending on how the URLs need to be, you could use two different entry types in the same channel or structure. If you need different URL structure you could always use {type} in the 'Entry URL Format' setting and then use custom routes if needed.

Hope this helps :)

I don't think you need to get as complex with arrays or anything.


---

### Answer by username_2 on 2015-06-04. Score: 1

To list entries of two sections in alternating order, I would do this.
Use the ids method to get an array of entry IDs for both of your sections. Then combine those arrays of IDs by iterating over a sequence '0..x', and for each step pull one ID from each of the individual arrays with merge. You can now use that array of IDs in a new ElementCriteriaModel to get the entries you're after.
{% set galleryEntriesIds = craft.entries.section('gallery').limit(null).ids() %}
{% set updateEntriesIds = craft.entries.section('update').limit(null).ids() %}

{% set mixedEntriesIds = [] %}

{% for key in 0..50 %}

    {% if galleryEntriesIds[key] is defined %}
        {% set mixedEntriesIds = mixedEntriesIds|merge(galleryEntriesIds[key]) %}
    {% endif %}

    {% if updateEntriesIds[key] is defined %}
        {% set mixedEntriesIds = mixedEntriesIds|merge(updateEntriesIds[key]) %}
    {% endif %}

{% endfor %}

{% set mixedEntries = craft.entries.id(mixedEntriesIds).fixedOrder(true) %}

Use getSection to check which section an entry belongs to within your loops.
{% paginate mixedEntries as entriesOnPage %}
    {% for entry in entriesOnPage %}

        {% if entry.getSection().handle == 'gallery' %}
            ...
        {% else %}
            ...
        {% endif %}

    {% endfor %}
{% endpaginate %}


---

