# Display list of posts by tag, BUT ONLY if in a specific category

**URL:** <https://talk.jekyllrb.com/t/display-list-of-posts-by-tag-but-only-if-in-a-specific-category/8745>\
**Category:** Help\
**Created:** [December 4, 2023, 3:51pm UTC](https://talk.jekyllrb.com/t/display-list-of-posts-by-tag-but-only-if-in-a-specific-category/8745 "2023-12-04T15:51:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dre](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/dre/32/5185_2.png) [@dre](https://talk.jekyllrb.com/u/dre)\
**Post date:** [December 4, 2023, 3:51pm UTC](https://talk.jekyllrb.com/t/display-list-of-posts-by-tag-but-only-if-in-a-specific-category/8745/1 "2023-12-04T15:51:17Z")

</div>

So i [use this today for a tag list](https://andresanz.com/blog/tags/) and it works fine, but i’d like to layer on an additional filter to show me that exact list but for only posts of a specific category. Here’s the mess i have so far:

```auto
<div class="p-3 border rounded-1 bg-light mt-2">
			
			
			{% assign sorted_tags = site.tags | sort %}
			{% for tag in sorted_tags %}
			
			{% assign zz = tag[1] | sort %}
			{% if zz != empty %}
			
			<a href="#" class="tagpagescroll" id="{{ tag[0] | replace: " ","-" | downcase }}" style="text-decoration: none; cursor:default; color: black; font-weight: 600;">{{ tag[0] | downcase }}</a>
			<ul class="taglist">
				
				
				{% for p in zz %}
				
				
				{% assign category_name = site.categories | sort %}
				{% for category in category_name %}
				
				{% assign yy = category[1] | sort %}
				{% if yy != empty %}
				
				{% if categories == "posts" %}
				POSTS
				{% endif %}
				
				{% if category[0] == "photos" %}
				PHOTOS
				{% endif %}
				
				{% if category[1] == "writing" %}
				WRITING
				{% endif %}
				
				{% endif %}

				
				<li class="taglist"><a href="{{ p.url }}" class="as-menu-link">{{ p.title }}</a> <span class="tag-index-meta">{% include tag-index-meta.html %}</span></li>
				
				
				{% endfor %}
				
				
			</ul>
			
			{% endif %}
			{% endfor %}
			{% endfor %}
		</div>	
	</div>

```

Thanks for taking a look… Andre

---

<div class="post-metadata">

**Author:** ![rdyar](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/rdyar/32/710_2.png) [@rdyar](https://talk.jekyllrb.com/u/rdyar)\
**Post date:** [December 4, 2023, 8:51pm UTC](https://talk.jekyllrb.com/t/display-list-of-posts-by-tag-but-only-if-in-a-specific-category/8745/2 "2023-12-04T20:51:42Z")

</div>

> [@dre](#):
>
> `assign zz = `

lol, I’d recognize my code any where, this is from a post on stackoverflow right?? naming things is **hard**.

are you trying to do this once for only one category?

what did you get with the code now? does POSTS output?

You might want to output the value of zz and yy to better understand what they contain.
