Displaying all posts with certain words in Title

Hi All,

I was hoping that you could help me write some code that allows me to output all the posts with a certain word within its’ name; (if it helps I am going to be hosting on GithubPages) I have code to display all the posts and their categories but I don’t think that categories is the way to go about this because then I would need multiple categories and I don’t think that this is possible. The next best way to go about doing this (in my opinion) is to look for buzzwords in the title. E.g. Dog, Cat, on one page I want to display all the posts that have the word DOG in it’s title.

Kind Regards
Aiyush

Use one or more tags similar to categories.

Note you can have multiple categories but they affect the path the post as /catA/catB/post.html while tag does not

@MichaelCurrin I was going to use tags, however, I was going to host my blog on GithubPages- as far as I am aware you cannot have tags in GithubPages, hence categories. Do you know any good resources to educate me on how to use multiple categories.

Kind Regards
Aiyush

I have this code here:

---
title: "Tags"
layout: default
permalink: "/tags.html"
---

{% for tag in site.tags %}
<h4 class="mt-5 mb-neg-30" id="{{ tag[0] | replace: " ","-" }}"><span class="text-capitalize text-small badge badge-primary">{{ tag[0] }}</span></h4>
<div class="blog-grid-container">
{% assign pages_list = tag[1] %}
{% for post in pages_list %}
{% if post.title != null %}
{% if group == null or group == post.group %}
{% include postbox.html %}
{% endif %}
{% endif %}
{% endfor %}
{% assign pages_list = nil %}
{% assign group = nil %}
</div>
{% endfor %}

But it outputs all of the tags content --> how can I edit this so that it only displays said tags post e.g. all tags tagged with dog

Oh I had no idea.

Here’s a work around.

Though it might be less code to setup github actions - for a deploy of jekyll with custom plugins. See the CI Github section of jekyll docs

For categories, add comma separated values and you can iterate over all categories available and posts in each.

Regarding your snippet replace postbox with a list item

<h2>{{ tag[0]}}</h2>

<ul>
{% for  ... %}
<li>{{ post.title }}</li>
{% endfor %}
</ul>

Hi @MichaelCurrin turned out I was incorrect about the tags in Github Pages as another person in this forum kindly told me:

Tags are supported. What isn’t supported are plugins that auto generate tag based archives for you.

Hi @MichaelCurrin I have tried that but it doesn’t output the correct thing. I am using the theme memoirs which can be found here, to reiterate what I would like to happen, I want to be able to specify a tag e.g. France and all the posts tagged with France to be displayed, however, I would like them to do so in the format of the image that is displayed but without the other tags being displayed. Please see the image attached for a reference:

(That was a zoomed out image because I needed to show that there was a movies tag at the bottom and its’ posts which I don’t want to be there).

I tried adding

<h2>{{ tag[0]}}</h2>

<ul>
{% for  ... %}
<li>{{ post.title }}</li>
{% endfor %}
</ul>

Into my code, like this:

---
title: "Tags"
layout: default
permalink: "/tags.html"
---

{% for tag in site.tags %}
<h4 class="mt-5 mb-neg-30" id="{{ tag[0] | replace: " ","-" }}"><span class="text-capitalize text-small badge badge-primary">{{ tag[0] }}</span></h4>
<div class="blog-grid-container">
{% assign pages_list = tag[1] %}
{% for post in pages_list %}
{% if post.title != null %}
{% if group == null or group == post.group %}

<h2>{{ tag[0]}}</h2>

<ul>
{% for post in site.tags.France %}
<li>{{ post.title }}</li>
{% endfor %}
</ul>

{% endif %}
{% endif %}
{% endfor %}
{% assign pages_list = nil %}
{% assign group = nil %}
</div>
{% endfor %}

But as you can see (I am a noob) I am not sure what to replace the for... with.

Thanks for your help so far.

Kind Regards
Aiyush :grinning:

EDIT:
If it helps, here is the code for the _includes postbox.html

<!-- begin post -->
{% assign author = site.authors[post.author] %}

<div class="blog-grid-item">
    <div class="card h-100">
        <div class="maxthumb">
            <a href="{{ site.baseurl }}{{ post.url }}">
                {% if post.image %}

                    {% if site.lazyimages == "enabled" %}
                        <img class="img-thumb lazyimg" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAMAAAACCAQAAAA3fa6RAAAADklEQVR42mNkAANGCAUAACMAA2w/AMgAAAAASUVORK5CYII=" data-src="{% if post.image contains "://" %}{{ post.image }}{% else %}{{ site.baseurl }}/{{ post.image }}{% endif %}" alt="{{ post.title }}">
                    {% else %}
                        <img class="img-thumb" src="{% if post.image contains "://" %}{{ post.image }}{% else %}{{ site.baseurl }}/{{ post.image }}{% endif %}" alt="{{ post.title }}"> 
                    {% endif %}

                {% endif %}
            </a>
        </div>
        <div class="card-body">
            <h2 class="card-title">
                <a class="text-dark" href="{{ site.baseurl }}{{ post.url }}">{{ post.title }}</a>
                {% if post.rating %}
                <div class="mb-2 mt-2 font-weight-normal">
                {% include star_rating_postbox.html %}
                </div>
                {% endif %}
            </h2>
            <h4 class="card-text">{{ post.excerpt | strip_html | truncatewords:30 }}</h4>
        </div>
        <div class="card-footer bg-white">
            <div class="wrapfooter">
                {% if post.author %}
                <span class="meta-footer-thumb">
                {% if author.avatar %}
                <img class="author-thumb" src="{{site.baseurl}}/{{ author.avatar }}" alt="{{ author.display_name }}">
                {% else %}
                <img class="author-thumb" src="https://www.gravatar.com/avatar/{{ author.gravatar }}?s=250&d=mm&r=x" alt="{{ author.display_name }}">
                {% endif %}
                </span>
                <span class="author-meta">
                <span class="post-name"><a target="_blank" href="{{ author.web }}">{{ author.display_name }}</a></span> 
                {% endif %}
                <span class="post-date">{{ post.date | date_to_string }}</span>
                </span>
                <div class="clearfix"></div>
            </div>
        </div>
    </div>
</div>
<!-- end post -->

Because you can’t use plugins you’ll need to create a page for every “tag archive”. In your case you’ll need a page for “Posts tagged France”.

Simple example would be something like creating a page named france.md and having this for loop

{% for tag in site.tags[France] %}
  ...
{% endfor %}

Inside the for loop you’d have your layout for each teaser block.

I have tried to do this:

---
layout: default
title: France
permalink: /franceTags
---

{% for tag in site.tags[France] %}
  <p>Test</p>
{% endfor %}

However, nothing shows up on the page, not even ‘test’ and their are definitely posts with the tag France.
Could you please help?

{% for tag in site.tags %}
  <p>Test</p>
{% endfor %}

Seems to work fine and output Test 2 times (since I have two categories in total)
But site.tags[France] doesn’t?

EDIT:
It now works with:

{% for tag in site.tags.France %}
  <p>Test</p>
{% endfor %}

Do have posts that are tagged with tags: France? If not then no posts will show.
Tags are case sensitive

You’ll want the following in your post’s YAML Front Matter:

tags: [France]

Or

tags:
  - France

@mmistakes Yeah, I have them there. I can get the posts to iterate through the number of posts tagged France (at the moment for every one post named France it displays test) however, I cannot get the preview of the post to show like it did last time. Do you think that you could mess around with it to see if you could get it working? It would be much appreciated. All of the code can be found here: http://jekyllthemes.org/themes/memoirs-jekyll-theme/

Thanks in advance
Aiyush