2

Another easy question for you all.... I'm trying to display all entries in a specific category. I'm using the below code from the Craft site, but not sure what I'm missing. I'm replacing the "entries" in the output section with the category name.

{% set entries = craft.entries.relatedTo(category) %}

{% for entry in entries %}
    <a href="{{ entry.url }}">{{ entry.title }}</a>
{% endfor %}

Thank you...

1

You need to set the category variable.

In this example, I'm using a slug:

{% set category = craft.categories.slug('catSlug') %}

So full code:

{% set category = craft.categories.slug('catSlug') %}
{% set entries = craft.entries.relatedTo(category) %}
{% for entry in entries %}
    <a href="{{ entry.url }}">{{ entry.title }}</a>
{% endfor %}
| improve this answer | |
  • Bravo...... you guys on here are so helpful. I really appreciate all the help.. One more, if I want to limit/offset the output.? Thanks Again.. – fidel Jul 7 '16 at 21:41
  • Found the second part out... Thanks again. – fidel Jul 7 '16 at 22:27
  • I just started using Craft myself. So learning together is a good thing! Glad you got it figured out. Everything seems to work around the different content models. Once you get a grasp of that, it falls into place. – Erik Jul 8 '16 at 1:32

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.