<p>You can't do this with the criteria parameters offset and limit. I would suggest to first get all the IDs of your section and then use Twig's handy <a href="http://twig.sensiolabs.org/doc/functions/cycle.html" rel="nofollow"><code>cycle</code></a> function to get those entry IDs you're interested in.</p>

<p>That function starts to read an array from the beginning again, when it reaches it end, so that's exacly what you need here. So when you want to get the 8th element of an array of length 7, it returns the first element (monday)!</p>

<p>The first element / ID of your array is in position 0, so I sustracted 1 from the week day number before passing it to the <code>cycle</code> function.</p>

<pre><code>{% set allIds = craft.entries.section('schedule').ids() %}
{% set nextIds = [] %}

{% set start = now|date('w') - 1 %}
{% set end = start + 2 %}

{% for i in start..end %}
    {% set id = cycle(allIds, i) %}
    {% set nextIds = nextIds|merge([id]) %}
{% endfor %}

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

CC BY-SA 3.0
2015-08-27T14:18:40.063Z
2015-08-27T14:23:53.760Z
2015-08-27T14:23:53.760Z
carlcs
<p>I have a structure that I am using for a schedule, it has 1 entry per day (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday). </p>

<p>What I want to do is only show the 3 days from the current day. </p>

<p>i.e if today is Thursday, it will show the Thursday, Friday &amp; Saturday entries. </p>

<p>I have used the following to control the offset which works great. </p>

<pre><code>{% for entry in craft.entries.section('schedule').offset(now|date('w')).limit(3).find() %}
</code></pre>

<p>My problem is, when I get to Friday or Saturday it wont show Sunday because that is the first entry of the structure. </p>

<p>Is there anyway I can have it loop around to start the list of entries again?</p>

<entries><structure><loop>
Repeat entries but starting from offset
# Repeat entries but starting from offset

(Asked by: username_0 on 2015-08-27)

I have a structure that I am using for a schedule, it has 1 entry per day (Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday). 
What I want to do is only show the 3 days from the current day. 
i.e if today is Thursday, it will show the Thursday, Friday & Saturday entries. 
I have used the following to control the offset which works great. 
{% for entry in craft.entries.section('schedule').offset(now|date('w')).limit(3).find() %}

My problem is, when I get to Friday or Saturday it wont show Sunday because that is the first entry of the structure. 
Is there anyway I can have it loop around to start the list of entries again?

**Tags:** entries, structure, loop


---

## 1 answers

### Answer by username_1 on 2015-08-27. Score: 2 | Accepted answer

You can't do this with the criteria parameters offset and limit. I would suggest to first get all the IDs of your section and then use Twig's handy cycle function to get those entry IDs you're interested in.
That function starts to read an array from the beginning again, when it reaches it end, so that's exacly what you need here. So when you want to get the 8th element of an array of length 7, it returns the first element (monday)!
The first element / ID of your array is in position 0, so I sustracted 1 from the week day number before passing it to the cycle function.
{% set allIds = craft.entries.section('schedule').ids() %}
{% set nextIds = [] %}

{% set start = now|date('w') - 1 %}
{% set end = start + 2 %}

{% for i in start..end %}
    {% set id = cycle(allIds, i) %}
    {% set nextIds = nextIds|merge([id]) %}
{% endfor %}

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


---

