1

How do I publish a list of three most recent entries within a 'blog' section that feature the category id '42'?

I presently have this code:

{% for entry in craft.entries.section('blog').limit(3).find() %}
    <li>
        <a href="{{ entry.url }}">{{ entry.title }}</a>
    </li>
{% endfor %}

However, I am having trouble properly implementing the .relatedTo() filter within this snippet, and all of the examples that I have read reference a category title rather than id.

2

You can pass in a CategoryModel to the relatedTo parameter, so its just a matter of getting the CategoryModel you're after. Something like:

{% set category = craft.categories.id(42).first %}
{% set entries = craft.entries.section('blog').limit(3).relatedTo(category) %}

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.