<p>You could do multiple "for" loops on the first craft.entries request using limits and offsets:</p>

<pre><code>{% set posts = craft.entries.section('posts') %}

{# ROW ONE #}
{% for post in posts.limit(1) %}
   html stuff for first post
{% endfor %}

{% for post in posts.limit(2).offset(1) %}
   html stuff for 2nd and 3rd posts skipping 1
{% endfor %}

{# ROW TWO #}
{% for post in posts.limit(2).offset(3) %}
   html stuff for 4th and 5th posts skipping 3
{% endfor %}
</code></pre>

<p>etc.</p>

<p>For the switching back and forth between horizontal and vertical, you can set up a couple of macros and call them where needed(or includes for that matter, lots of ways to skin this cat).</p>

<pre><code>{% macro vertical(url, title) %}
&lt;li&gt;
    &lt;a href="{{ url }}" title="{{ title }}"&gt;{{ title }}&lt;/a&gt;
&lt;/li&gt;
{% endmacro %}

{% macro horizontal(url, title) %}{# different html #}
&lt;div&gt;
    &lt;h1&gt;{{ title }}&lt;/h1&gt;
    &lt;a href="{{ url }}"&gt;Learn More&lt;/a&gt;
&lt;/div&gt;
{% endmacro %}
</code></pre>

<p>and then where you need them in the first part of your question above:</p>

<pre><code>{% for post in posts.limit(2).offset(3) %}
   {{ _self.vertical(post.url, post.title) }}
{% endfor %}
</code></pre>

<p>and</p>

<pre><code>{% for post in posts.limit(2).offset(3) %}
   {{ _self.horizontal(post.url, post.title) }}
{% endfor %}
</code></pre>

<p><a href="http://twig.sensiolabs.org/doc/tags/macro.html" rel="nofollow">Twig Macros</a></p>

<p><a href="https://mijingo.com/blog/using-macros-in-twig-and-craft" rel="nofollow">Using Macros by Mijingo</a></p>

<p>alternatively with includes</p>

<pre><code>{% for post in posts.limit(2).offset(1) %}
  {% include "_includes/vertical_layout" %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2016-08-27T19:59:55.520Z
Bingo.  I used includes with no issues.  Macros are still a bit intimidating (for now at least).
Hellyar
CC BY-SA 3.0
2016-08-24T23:02:39.863Z
2016-08-25T00:13:51.347Z
2016-08-25T00:13:51.347Z
AbbeyDesign
<p>I have a grid.  The pattern is:</p>

<ul>
<li><code>**Row 1**</code> = <code>1 x featured post</code> and <code>2 x vertical posts</code>.  (The feature is the equivalent of 2 vertical posts.) </li>
<li><code>**Row 2**</code> = <code>2 x horizontal posts</code>  <code>Row 2</code> starts with the <code>4th most recent post</code>.</li>
<li><code>**Row 3**</code> = <code>4 x vertical posts</code></li>
<li><code>**Rows 4-n**</code> repeat <code>Row 2</code> and <code>Row 3</code>...</li>
</ul>

<p>I have experimented with <code>{% if loop.index is divisible by(2) %}stuff{% else %}other-stuff{% endif %}</code> to switch between the horizontal and vertical alignments.   </p>

<p>So, this is a 2 part question.</p>

<ol>
<li>How do I pull the 2nd and 3rd most recent posts to populate the 2 vertical posts in <code>Row 1</code>? </li>
</ol>

<p>I am already calling the <code>featured post</code> using <code>{% for post in craft.entries.section('posts') %}{% if loop.first and craft.request.pageNum == 1 %}</code>...  </p>

<ol start="2">
<li>Next, how do I then tell Craft to populate 2 horizontals in <code>Row 2</code> and then switch to 4 verticals in <code>Row 3</code>?   I assume its best to separate step #1 from step #2 which would require <code>Row 2</code> to start with <code>4th most recent post</code></li>
</ol>

<templating>
How do you tell Craft to change post directions from row-to-row?
# How do you tell Craft to change post directions from row-to-row?

(Asked by: username_0 on 2016-08-24)

I have a grid. The pattern is:

* `**Row 1**` = `1 x featured post` and `2 x vertical posts`. (The feature is the equivalent of 2 vertical posts.)
* `**Row 2**` = `2 x horizontal posts` `Row 2` starts with the `4th most recent post`.
* `**Row 3**` = `4 x vertical posts`
* `**Rows 4-n**` repeat `Row 2` and `Row 3`...

I have experimented with `{% if loop.index is divisible by(2) %}stuff{% else %}other-stuff{% endif %}` to switch between the horizontal and vertical alignments.

So, this is a 2 part question.

1. How do I pull the 2nd and 3rd most recent posts to populate the 2 vertical posts in `Row 1`?

I am already calling the `featured post` using `{% for post in craft.entries.section('posts') %}{% if loop.first and craft.request.pageNum == 1 %}`...

2. Next, how do I then tell Craft to populate 2 horizontals in `Row 2` and then switch to 4 verticals in `Row 3`? I assume its best to separate step #1 from step #2 which would require `Row 2` to start with `4th most recent post`

**Tags:** templating


---

## 1 answers

### Answer by username_1 on 2016-08-24. Score: 3 | Accepted answer

You could do multiple "for" loops on the first craft.entries request using limits and offsets:
{% set posts = craft.entries.section('posts') %}

{# ROW ONE #}
{% for post in posts.limit(1) %}
   html stuff for first post
{% endfor %}

{% for post in posts.limit(2).offset(1) %}
   html stuff for 2nd and 3rd posts skipping 1
{% endfor %}

{# ROW TWO #}
{% for post in posts.limit(2).offset(3) %}
   html stuff for 4th and 5th posts skipping 3
{% endfor %}

etc.
For the switching back and forth between horizontal and vertical, you can set up a couple of macros and call them where needed(or includes for that matter, lots of ways to skin this cat).
{% macro vertical(url, title) %}

    {{ title }}

{% endmacro %}

{% macro horizontal(url, title) %}{# different html #}

    {{ title }}
    Learn More

{% endmacro %}

and then where you need them in the first part of your question above:
{% for post in posts.limit(2).offset(3) %}
   {{ _self.vertical(post.url, post.title) }}
{% endfor %}

and
{% for post in posts.limit(2).offset(3) %}
   {{ _self.horizontal(post.url, post.title) }}
{% endfor %}

Twig Macros
Using Macros by Mijingo
alternatively with includes
{% for post in posts.limit(2).offset(1) %}
  {% include "_includes/vertical_layout" %}
{% endfor %}

> **Comments:**
> **username_0**: Bingo.  I used includes with no issues.  Macros are still a bit intimidating (for now at least).  

---

