<p>Entirely possible I'm misunderstanding what you're looking for, but I think something like this should do it:</p>

<pre><code>{% set entries = craft.entries.section('news').order('articleOrder desc').find() %}
{% set matchCount = 0 %}

{% for entry in entries %}
    {% if entry.currentYear2 == currentEdition.currentYear2 and currentEdition.currentMonth2 in entry.currentMonth2 and matchCount &lt;= 5 %}
        {% set matchCount = matchCount + 1 %}
        &lt;h2&gt;{{ entry.title }}&lt;/h2&gt;
    {% endif %}          
{% endfor %}
</code></pre>

CC BY-SA 3.0
2017-07-02T16:03:49.717Z
Thank you, that worked perfect, and I would never have figured that out on my own!
afc
CC BY-SA 3.0
2017-07-02T18:24:39.723Z
I am having the same problem with offset(5) as opposed to limit. Issue is, that I am failing to understand how your fix works, therefor I can't make it happen for offset.
afc
CC BY-SA 3.0
2017-07-02T00:28:06.813Z
2017-07-02T00:28:06.813Z
Brad Bell
<p>I've created two global variables which my content creator is going to use to turn off a bunch of articles and turn on a bunch more which a slight change in the Global.  I have a page where there is a limit of 5 of these articles.</p>

<pre><code>{% set entries = craft.entries.section('news').order('articleOrder desc').limit(5).find() %}

{% for entry in entries if entry.currentYear2 == currentEdition.currentYear2 and currentEdition.currentMonth2 in entry.currentMonth2 %}
    &lt;h2&gt;{{ entry.title }}&lt;/h2&gt;          
{% endfor %}
</code></pre>

<p>The problem with this is that the conditional only gets 5 entries to compare, and not the entire bunch. I want to first run an if statement on all the entries, then let me do a for loop with a .limit(5). I am not sure how to go about this. A conditional combined with a for loop in the same statement did not work either.</p>

<conditional><forloop><limit>
For loop, if statement, then limit
# For loop, if statement, then limit

(Asked by: username_0 on 2017-07-01)

I've created two global variables which my content creator is going to use to turn off a bunch of articles and turn on a bunch more which a slight change in the Global.  I have a page where there is a limit of 5 of these articles.
{% set entries = craft.entries.section('news').order('articleOrder desc').limit(5).find() %}

{% for entry in entries if entry.currentYear2 == currentEdition.currentYear2 and currentEdition.currentMonth2 in entry.currentMonth2 %}
    {{ entry.title }}          
{% endfor %}

The problem with this is that the conditional only gets 5 entries to compare, and not the entire bunch. I want to first run an if statement on all the entries, then let me do a for loop with a .limit(5). I am not sure how to go about this. A conditional combined with a for loop in the same statement did not work either.

**Tags:** conditional, forloop, limit

---

## 1 answers

### Answer by username_1 on 2017-07-02. Score: 0 | Accepted answer

Entirely possible I'm misunderstanding what you're looking for, but I think something like this should do it:
{% set entries = craft.entries.section('news').order('articleOrder desc').find() %}
{% set matchCount = 0 %}

{% for entry in entries %}
    {% if entry.currentYear2 == currentEdition.currentYear2 and currentEdition.currentMonth2 in entry.currentMonth2 and matchCount <= 5 %}
        {% set matchCount = matchCount + 1 %}
        {{ entry.title }}
    {% endif %}          
{% endfor %}

> **Comments:**
> **username_0**: Thank you, that worked perfect, and I would never have figured that out on my own!  
> **username_0**: I am having the same problem with offset(5) as opposed to limit. Issue is, that I am failing to understand how your fix works, therefor I can't make it happen for offset.  

---

