CMS Development

bengoshow
Participant | Partner
Participant | Partner

manipulating array data returned by 'blog_recent_posts'

SOLVE
I'm using `blog_recent_posts` but need to break up the data returned for display in different parts of the page. How can I use the Hubl `pop` function to remove the first element of the returned list of posts? Right now it removes the entire object.
 

The goal is to show 9 unique items "below the fold", instead of repeating ones already displayed above.

0 Upvotes
1 Accepted solution
piersg
Solution
Key Advisor

manipulating array data returned by 'blog_recent_posts'

SOLVE

You could loop twice, the first time returning only the first item, the second time returning all but the first. Either {% unless loop.first %} for everything but the first item or {% loop.index > 1 and loop.index <= 10 %} for the next 9 after the first.

{% set rec_posts = blog_recent_posts('default') %}
{% for rec_post in rec_posts %}
  {% if loop.first %}
    <div class="post-title">{{ rec_post.name }}</div>
  {% endif %}
{% endfor %}
 ...
{% for rec_post in rec_posts %}
  {% if loop.index > 1 and loop.index <= 10 %} // to return 9 posts but not the the first
    <div class="post-title">{{ rec_post.name }}</div>
  {% endif %}
{% endfor %}

 

View solution in original post

0 Upvotes
1 Reply 1
piersg
Solution
Key Advisor

manipulating array data returned by 'blog_recent_posts'

SOLVE

You could loop twice, the first time returning only the first item, the second time returning all but the first. Either {% unless loop.first %} for everything but the first item or {% loop.index > 1 and loop.index <= 10 %} for the next 9 after the first.

{% set rec_posts = blog_recent_posts('default') %}
{% for rec_post in rec_posts %}
  {% if loop.first %}
    <div class="post-title">{{ rec_post.name }}</div>
  {% endif %}
{% endfor %}
 ...
{% for rec_post in rec_posts %}
  {% if loop.index > 1 and loop.index <= 10 %} // to return 9 posts but not the the first
    <div class="post-title">{{ rec_post.name }}</div>
  {% endif %}
{% endfor %}

 

0 Upvotes