Collect Items from Multiple Collections and Organize by Tag

Hello,

I have a website for a conference and I’m using two collections to organize the content: posters and visualizations. I’d like to create a page that indexes content from both collections and organizes them by tag. I’m currently collecting tags by searching: {% for post in site.posters %}

It’s working fine for one collections, but I’m hoping to intermingle content from both collections so that people can browse by subject tag. Is it possible to return content from more that one collection?

Here’s the page where I’m trying to display the index.

Thanks in advance for any leads.

Okay. I think I figured it out. I just repeated the {% for post in ... %} statement for each collection in the proper section. Maybe there’s a more elegant way, but here’s my solution.

Liquid has some filters that might help you combine site.posters and site.visualizations.

I’ve never used concat but it seems like a possible solution.

2 Likes

thanks! also found that the jekyll variable site.documents can be super helpful here.

As @chrisdaaz suggested, you can use site.documents plus additional filtering:

{% assign alldocs = site.documents | <additional standard filtering and sorting> %}	
{% assign grouptag =  alldocs | map: 'tags' | join: ','  | split: ','  | group_by: tag %}
{%- for tag in grouptag -%}
    <h1>{{- tag.name -}} - {{tag.size}}</h1>
	{%- for document in alldocs -%}
    	{% if document.tags contains tag.name %}
        	 <p>{{- document.title -}}
		 {% endif %}
    {%- endfor -%}
{%- endfor -%}

Live example of a tag cloud including all the content of my blog (posts and projects) here.

1 Like