Skip to main content
1 of 2
user2569
  • 457
  • 2
  • 8

Display entries sharing the same nested category on an entry page

I'm trying to show the other entries assigned to the same nested category (on an entry template) but get an error if I use .last() which I was hoping would show the nested category assigned entries (and not all assigned to all levels of the same category, Any ideas?

{# set the category group #}
{% set categoryGroup = craft.categories.group('products') %}
{% set entries = craft.entries.relatedTo(categoryGroup)  %}  
{# only show entries assigned to the same nested category #}
{% for sameCat in entries.last()  %}  
    <p>{{ sameCat.title }}</p>
{% endfor %}
{# note: using .last throws error – Impossible to access an attribute ("title") on a string variable ("1").
 #}
user2569
  • 457
  • 2
  • 8