3

I would like to loop through entries in a channel but only the ones for a specific entry type. Is this Possible?

I'm using the free version of craft on a test site, I have used the channel for my pages but also want to set up a blog. I have set up a blogPost entry type, is there a way to target this in a loop?

2 Answers 2

14
{% set entries = craft.entries.section('pages').type('blogPost') %}

{% for entry in entries %}
   {{ entry.title }}
{% endfor %}

Is what I have cobbled together... any pointers on improvements would be welcome.

2
  • 2
    That's exactly how to do it!
    – Brad Bell
    Commented Jul 5, 2014 at 13:32
  • Cheers Brad much appreciated. Commented Jul 5, 2014 at 19:43
1

Updating for Craft3 and calling for different types, I wanted to share how I use the entry types to create different header/slider entry.

{% set slides = craft.entries().section('slider') %}
{% set entries = slides.all() %}
{% for entry in entries %}
    {% if entry.type == 'type1' %}
        {# Your content for 'type1' Entry here #}
    {% endif %}
    {% if entry.type == 'type2' %}
        {# Your content for 'type2' Entry here #}
    {% endif %}
    {% if entry.type == 'type3' %}
        {# Your content for 'type3' Entry here #}
    {% endif %}
{% endfor %} 

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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