Filter topic with specific tag inside single category

Hello @Sarah_Knapp

You can use this to achieve the desired result.

<script type="text/discourse-plugin" version="0.8">
api.modifyClass("component:topic-list-item", {
  didInsertElement: function() {
    category = this.parentView.get("category");

    if (category) {
      categoryName = category.slug;
      tags = this.get("topic.tags");

      if (tags.length != 0) {
        categoryTags = function() {
          tag = $(".discourse-tag:not(.new-href)");
          $.each(tag, function() {
            href = $(this)
              .attr("href")
              .split("/");
            newHref = "/" + href[1] + "/c/" + categoryName + "/" + href[2];
            $(this)
              .addClass("new-href")
              .attr("href", newHref);
          });
        };
        api.addTagsHtmlCallback(categoryTags);
      }
    }
  }
});
</script>

You only need to add it to the common header section of a theme component.

If you’re not sure, have a look at our guide for using Discourse themes.

Here’s a small demo on theme creator where you can see it live. You need to navigate to the junk category and click on one of the tags there.

5 Likes