I want to create a blog listing that goes like this (row by row):
Article 1 - 'Feature Pick' tagged Post.
Articles 2,3,4 - 3 Next most recent articles.
CTA.
All other Articles .
I am nearly there using this:
{% set rec_posts = blog_recent_posts('default', 99) %}
{% for post in rec_posts %}
{% if 'Editors Pick' in post.topic_list|map('name') %}
// Article 1 - 'Feature Pick' tagged Post
{% endif %}
{% endfor %}
{% for post in rec_posts %}
{% if loop.index in range(1,4) %}
{% if 'Editors Pick' not in post.topic_list|map('name') %}
// Articles 2,3,4 - Next most recent articles
{% endif %}
{% endif %}
{% endfor %}
CTA.
{% for post in rec_posts %}
{% if loop.index in range(4,99) %}
{% if 'Editors Pick' not in post.topic_list|map('name') %}
// All other Articles
{% endif %}
{% endif %}
{% endfor %}
But am finding that becuase my 'Feature Pick' is techincally within the range (1,4) I am only getting 2 articles on that row. I could adjust it to range(1,5) but as soon as the article becomes older that system will break.
I am sure there is a better way of doing this if anyone could help I would be grateful.
Try something like this. Be sure to set the range and don't forget that tags are case sensitive.
{# First loop: featured posts #}
{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name == 'Featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
{# CTA GOES HERE #}
{% for content in contents %}
{% if loop.index in range(X,X) %}
{% for topic in content.topic_list %}
{% if topic.name != 'Featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
{# The rest of the posts #}
{% for content in contents %}
{% if loop.index in range(X,99) %}
{% for topic in content.topic_list %}
{% if topic.name != 'Featured' %}
{# Add your markup here #}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}
Thank you for your continued support @erod. I guess this comes down to whether, in the statement below, a 'Featured' article would be included within the count of a loop.index range even though we're not displaying it. I want to make sure I return 3 articles at this point. If the article is included I would only return 2?
{% for content in contents %}
{% if loop.index in range(1,4) %}
{% for topic in content.topic_list %}
{% if topic.name != 'Featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
{# First loop: featured posts #}
{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name == 'featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
{# Second loop: all other posts #}
{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name != 'featured' %}
{# Add the markup for the rest of your posts here #}
{% endif %}
{% endfor %}
{% endfor %}
Try something like this. Be sure to set the range and don't forget that tags are case sensitive.
{# First loop: featured posts #}
{% for content in contents %}
{% for topic in content.topic_list %}
{% if topic.name == 'Featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
{# CTA GOES HERE #}
{% for content in contents %}
{% if loop.index in range(X,X) %}
{% for topic in content.topic_list %}
{% if topic.name != 'Featured' %}
{# Add your featured post markup here #}
{% endif %}
{% endfor %}
{% endfor %}
{# The rest of the posts #}
{% for content in contents %}
{% if loop.index in range(X,99) %}
{% for topic in content.topic_list %}
{% if topic.name != 'Featured' %}
{# Add your markup here #}
{% endif %}
{% endfor %}
{% endif %}
{% endfor %}