1

I'm trying to include different markup if a blog post is featured. This is done via a Lightswitch. If there's is no featured entry then the latest entry uses this different markup instead. The rest of the entries follow this but need to exclude showing the featured entry if it is shown above.

This is something like what I'm trying to achieve

{% set featured = craft.entries.section('blog').featured(1).limit(1) %}
{% paginate craft.entries.section('blog').limit(12) as entriesOnPage %}
{% for entry in entriesOnPage %}
    {% if entry is featured or loop.first and not featured|length %}

       [markup A]

    {% else %}

       [markup B excluding featured item]

    {% endif %}
{% endfor %}
1

You could try this

{% set featured = craft.entries.section('blog').featured(1).count() %}
{% paginate craft.entries.section('blog').limit(12) as entriesOnPage %}
{% for index, entry in entriesOnPage %}
    {# entry is featured or it's the first entry and there are no other
    featured entries #}
    {% if entry.featured or (index == 0 and featured == 0) %}
        [markup A]
    {% else %}
        [markup B excluding featured item]
    {% endif %}
{% endfor %}
0

Based on the docs of the lightswitch field can't you just to this?

{% paginate craft.entries.section('blog').limit(12) as entriesOnPage %}
{% for entry in entriesOnPage %}
{% if entry.featured or loop.first and not entry.featured %}

This entry is featured. 

{% else %}

Entry isnt featured

{% endif %}
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.