Skip to main content
Bumped by Community user
added 10 characters in body
Source Link
Brad Bell
  • 67.6k
  • 6
  • 75
  • 145

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().last() which I was hoping would show the nested category assigned entries (and not all assigned to all levels of the same category, Any

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").
 #}

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").
 #}

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").
 #}
Source Link
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").
 #}