I'm trying to stay as DRY as possible here and sharing one template for a news list view; all, category and tag all sharing the same template (and trying to refrain from having a category or tag segment). My query isn't returning any results when the segment 2 (in this case the url encoded tag or category slug) when there is a tag and category that share the same name. Example, 'design' is a category for design related posts; 'design' is a tag for posts that featured a design service within the 'portfolio' category. My template code is below. Is there a work around here or do I need to have a second segment for tag/category (i.e. .com/news/category/design
and .com/news/tag/design
- or one or the other to differentialte)
{% if category is defined %}
{% set newsPosts = craft.entries.section('news').relatedTo(category).limit(5) %}
{% elseif tag is defined %}
{% set tag = craft.tags.groupId(3).name(tag).first() %}
{% set newsPosts = craft.entries.section('news').relatedTo(tag).limit(5) %}
{% else %}
{% set newsPosts = craft.entries.section('news').limit(5) %}
{% endif %}