So i'm trying to output blog entries related to a category.
- I first created a category group ('categories')
- I added several categories to the group ('innovation', 'teams', etc)
- I added a category field to my blog post matrix field (post.category)
On my blog index page (example.com/blog) I have excerpts of posts and a sidebar which has the categories and their urls
{% set categories = craft.categories.group('categories') %} {% for category in categories %} <li><a href="{{ category.url }}">{{ category.title }}</a></li> {% endfor %}
When I click on the link it goes to the page I expect (example.com/categories/teams) and is using the template i specified for the template group (categories.html)
In the template for the category I can list the title and name but I want to get the entries so I:
<h1>{{ category.title }}</h1> <--- just this works {% set posts = craft.entries.relatedTo(category) %} {% for post in posts %} <p>{{ post.title }}</p> {% endfor %}
But this didn't work
following http://buildwithcraft.com/help/entries-related-to-category
then I tried this, thinking specifying the field was necessary
<h1>{{ category.title }}</h1> <--- again, this works {% set posts = craft.entries({ section: 'blog', relatedTo: { targetElement: category, field: 'posts.categories' } }) %} {% for post in posts %} <p>{{ post.title }}</p> {% endfor %}
and this doesn't work either.
Anyways, i'm not sure where I am going wrong and any help would be appreciated.
{{ craft.entries.relatedTo(category).first().title }}
to the categories loop.{{ dump(posts) }}
?