Add an "All" link to the first-level forum next to the subcategory list?

So, I’ve got this going on on my category list:

image

and I notice that even though I know what the structure is, I’m drawn to selecting one of the subcategories rather than clicking on the big News & Announcements category. Is there a way I could easily add an “All” link that would go to News & Announcements - Fedora Discussion (same as clicking on the header) either before or after the subcategories?

1 Like

My current idea is to simply not allow posts in the top level, and to create a second-level news category under the first.

I’d love to hear any other ideas!

2 Likes

One thing you can try is to make the entire container clickable.

If you click on a subcategory, you get taken to it. If you click anywhere else inside the category container, you get taken to the parent category’s page.

This goes in the common > header tab.

<script type="text/discourse-plugin" version="0.8">
  const DiscourseURL = require("discourse/lib/url").default;

  api.modifyClass("component:categories-and-latest-topics", {
    pluginId: "clickable-category-boxes",
    click(event) {
      const target = event.target;

      const categoryContainer = target.closest("[data-category-id]");
      if (!categoryContainer) {
        return;
      }

      const isSubcategoryLink = target.closest(".badge-wrapper");
      if (isSubcategoryLink) {
        return;
      }

      const categoryLink = categoryContainer.querySelector(
        ".category-title-link"
      );

      const categoryURL = categoryLink.href;
      DiscourseURL.routeTo(categoryURL);
    },
  });
</script>

This goes in the common > CSS tab.

.category-list [data-category-id] {
  cursor: pointer;
}
1 Like