3

Trying to get 10 entries related to the current entry categories excluding a category called featured. I don't have the category name(s) in the url.

This currently what I tried but this does not work, confused about how to do this.

{# Fetch all of the categories related to this entry excluding the featured category#}
{% set categories = craft.categories.relatedTo(entry) %}

{# Output them #}
{% set thecategory = [] %}

{% for category in categories %}
    {% set thecategory = craft.categories.group('resource').slug(category.slug) %}
{% endfor %}

{# Set featured category name to exclude #}
{% set category = craft.categories.group('resource').title('featured') %}
{# Set featured ID's we dont want to show... #}
{% set featuredArticleIds = craft.entries.section('articles').relatedTo(category).ids() %}
{% set featuredArticleIdsString = featuredArticleIds | join(', not ') %}

{% set entries = craft.entries.section(articles).relatedTo('and', thecategory|join(',')).id('and, not '~featuredArticleIdsString).limit(10) %}
3

This solution should also remove your "featured" category entries:

{% set categories = craft.categories.relatedTo(entry) %}
{% set featuredCategory = craft.categories.slug('featured').first() %}

{% set allIds = [] %}
{% for id in categories.ids() if id != featuredCategory.id %}
    {% set allIds = allIds|merge([id]) %}
{% endfor %}

{% set entries = craft.entries.relatedTo(allIds) %}
  • Interesting, still getting featured though so not sure whats going on. – Bowenac Jul 31 '15 at 17:35
  • Updated! Hope this finally works for you now. :) – carlcs Jul 31 '15 at 17:51

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.