2

I have a category group set up called 'gists'. I have entries that contain a category field which pulls in the category group 'gists'.

Now I need to access entries that are tied to individual categories but I need to do so by the category slug.

I cannot figure out how to make this happen. I have tried numerous things but cannot get my head around this. Here is my latest.

{% for entry in craft.entries.section('gist').relatedTo('tech').limit(10).find() %}
3

Craft site has the excellent document How do I list the entries related to a category?

Building on that, you would fetch your category (by slug), and then the entries related to the category.

{# Fetch the category with slug 'categorySlug' #}
{% set category = craft.categories.slug('categorySlug').first() %}

{# Fetch all of the entries related to this category #}
{% set entries = craft.entries.relatedTo(category) %}

Then loop over those entries.

  • This worked. Not sure that I understand how. But not I have something to study. Thanks – David Aaron McInnis Aug 5 '14 at 19:12
  • 1
    @David If you're still trying to understand how categories work I would recommend looking through the questions on categories here on SE. There are some answers with very useful and basic examples. – Simon Kuran Aug 5 '14 at 19:20

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.