1

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) %}
    <div class="row">
    <div class="large-6 large-centered columns test">
    <article>
        <h3><a href="{{ entry.url }}">{{ entry.title }}</a></h3>
        <p>Posted on {{ entry.postDate.format('F d, Y') }}</p>
        {{ entry.body.getPage(1) }}
        <img src="{{ entry.mainFeaturedImage.first().url }}">
        <p><a href="{{ entry.url }}">Continue reading</a></p>
    </article>
</div>
</div>
{% endfor %}
{# end of story #}

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

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

{% endfor %}
{% endpaginate %}
</div>
  • Could you post the code to how your currently doing this to avoid a duplicate solution :) – Alec Ritson May 31 '15 at 14:39
  • @fishfillet still problems setting this up? – carlcs Jun 5 '15 at 4:17
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.

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 %}

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.