Category Banners

:discourse2: Summary Category Banners uses existing category details to create banners for your category pages. It uses the category name, description, and color to generate a banner at the top of the relevant category pages (for tags check out Discourse Tag Banners).
:eyeglasses: Preview Preview on theme-creator.discourse.org
:hammer_and_wrench: Repository Link https://github.com/discourse/discourse-category-banners
:open_book: New to Discourse Themes? Beginnerā€™s guide to using Discourse Themes

Install this theme component

The category description is defined by the first paragraph in each categoryā€™s ā€œCategory definition for ā€¦ā€ topic. The banner background/text colors are defined by your category badge settings.

By default this will display on desktop and mobile across all Category and Subcategory pages, but will not appear if you havenā€™t given your category a description.

This component comes with options to override the defaults:

  • Show description: disabling this will hide the description part of the banner.
  • Show mobile: disabling this will hide banners on mobile devices
  • Show subcategory: disabling this will hide banners for subcategories
  • Show category logo: enabling this will show the uploaded logo from the categoryā€™s settings
  • Align text: select left, center, or right text alignment
  • Hide if no description: disabling this will show banners even if a category description is not set
  • Exceptions: if you donā€™t want a category to have a banner, add its name here

If you want to customize these with some additional CSS you can target specific category headers by using this structure (example-category is your category name):

.category-title-header {
  &.category-banner-example-category {
        background: url(example.jpg);
  }
}

This component also adds the class category-header to the body tag as an additional CSS target.

95 Likes

thanks for this wonderful theme :heart:, it helps users to note the category description much easier.

currently if thereā€™s a link or a bold/italic word in the category description, in the banner itā€™ll appear as simple text (e.x. p style instead of a style). isnā€™t it better if the text style is preserved in the banner as well?

2 Likes

Hi, I absolutely love this component! Thanks for your work!

Iā€™m wondering, how can I style the background so that it automatically pulls the category background image and makes it the background of the banner. The backgrounds are already hidden anyways, so I want it to simply display as the background to the banner, rather than the page. Iā€™ve tried this, but it didnā€™t work and I think I might be targeting the wrong variable:

return h('div.category-title-header' + " ." + category.slug, {
                    "attributes" : {
                        "style" : "background-color: #" + category.color + "; color: #" + category.text_color + "; background-image: url(\'" + 
                        category.background_url + "\');"
                    }
                }

Also, Iā€™m wondering, how can I make the banner thinner for a fixed width design. When I attempted, it continued to be left-justified.

1 Like

I think itā€™s great that the category banners now render the content in HTML

Is there any way to display emojiā€™s there? In my case I added three important links: AnfƤnger - Cannabisanbauen.net Forum

I want to display the emojis next to each link as well. The original about topic is here: Ɯber die Kategorie AnfƤnger - AnfƤnger - Cannabisanbauen.net Forum

1 Like

Not prefixing the category name is a recipe for disaster, so Iā€™ve added category-banner- before the class name (e.g., category-banner-meta). If you were targeting the category name in your CSS youā€™ll just have to add category-banner- before it.

Iā€™m not sure, I donā€™t think our default category descriptions support them either, but I can look into itā€¦

5 Likes

I want to use the uploaded background image from the category to put it in the background of the banner. Iā€™ve edited the code and everything looks great. I wonder is there anything I can do to make the image load faster or together with the rest of the page? I want to avoid the flickering of the background for a second before the image appears.
Compressing image is certainly an option, but I wonder if there are others. Can I grab the thumbnail of the uploaded background image in the code? Thanks for all leads!

1 Like

Hello, and thank you for this theme component!

I just tried installing it, following this tutorial (did exactly the same steps) to try this Category Banners component, but nothing happens. No banner in any of the categories. Is there anything that I might have done that doesnā€™t make it work? The only explanation I see is that the ā€œbootstrapā€ warning blocks it?

1 Like

By default, the theme component does not display category banners if you have not set a category description for a category. This can be changed by unchecking the ā€œHide banners if category description not setā€ checkbox.

Category descriptions are set by editing the About category topic that Discourse automatically creates for every category. If you have either added category descriptions, or disabled the setting to hide banners for categories without descriptions, and you are still not seeing category banners, let us know. Weā€™ll look into what is going on.

6 Likes

Thank you for your answer. I have checked and confirm that each category on the forum has a description. The ā€œHide bannersā€¦ā€ option is now unchecked just to make sure but nothing changes.

As you can see on the images, everything looks normal in the settings :

No idea if it could have anything to do with the issue but just informing you itā€™s a Discourse installation on a Yunohost instance.

1 Like

Is there anyone other than me that thinks it would be nice to enable this same styling on Group listing pages (e.g. /g/foo) as well? The CSS, unfortunately, is not quite the same, and I guess it would require some additional handling of the various buttons to the right side of the group name, i.e., :bust_in_silhouette: Request:email: Message :garbage: Delete

It could go a long way for a consistent look and feel, and make groups feel more like a ā€œfirst classā€ citizen among the UI. (IMHO)

5 Likes

I love these category banners! Thank you for making this theme component!

I would love this banner to exist in the main home page of our forums where it shows:

  • ā€œLatestā€ Discussions or
  • ā€œTopā€ Discussions or
  • ā€œCategoriesā€ or
  • ā€œFollowingā€ (if youā€™re using the Follow Plugin :man:)

Would there be an easy (ish) way to have there be a banner if someone selected each of these options, respective to what was selected?

2 Likes

@awesomerobot , I hope you are okay with me sharing this hereā€¦

Iā€™ve created a fork of this discourse-category-banners theme called

discourse-category-banner-boxes
https://github.com/naidihr/discourse-category-banner-boxes

You can preview it here

https://theme-creator.discourse.org/theme/Rhidian/discourse-category-banner-boxes

It pretty much does the same thing but with some modifications:

  • The category banner box is displayed in-line above the main heading instead of full width at the top. This allows for display a banner theme at the top, for example the discourse-versatile-banner.

  • The category banner box is displayed in the same style as the native discourse subcategory boxes, which are a core component of discourse. These subcategory boxes are a display option in the discourse category settings Show subcategory list above topics in this category . This option displays the subcategory category name and description as a row or box above the topic list, using the category background colour as the left border.

  • If the category is a subcategory, the category name is displayed as breadcrumb as follows - Parent category name: Subcategory name

Demo screen shot of theme banner box for the category, above the native subcategory boxes.

Screen shot of the subcategory, showing the breadcrumb reference to the parent category.

This is my first attempt at a theme modification. I hope this is helpful?

Update

I have refactored this adaption as a separate component - with many additional features including using the category logo image and background image in the header. This new component effectively replaces the standard Discourse category header, unlike the category banners, hence making it a new component. Please see:

10 Likes

This isnā€™t working for us. Iā€™ve tried both the category slug and the category ID, but the banner stays stubbornly there. Is this working for anyone else?

3 Likes

I just tried it and it works for me, itā€™s looking for the case-sensitive category name. In retrospect that was not the best way to implement itā€¦ I can probably improve that.

3 Likes

Ah - that sort is for me! And you do state ā€˜nameā€™ in the guide above - I just didnā€™t read that.

Name isnā€™t very intuitive as we donā€™t really use it for anything else. But it is displayed a lot. Just making it more explicit in the settings would be fine I reckon.

1 Like

Instead of adding exceptions of what which categories will not show a given uploaded banner, canā€™t we just specify which category should show which banner?

2 Likes

Depends on the specific site and use-case Iā€™m sure. My initial thought was that it would be more likely for a site to want it implemented everywhere, and if there were exceptions it would only be a few.

If you wanted to implement a banner for a small number of categories there might be a better theme component option thatā€™s built to be a less generic cover-all, like Versatile Banner or customizing one of the options found in Banner themes (and instructions for customizing them)

4 Likes

would be great to be able to upload an image to replace the text.

1 Like

Thanks for that very usefull component!

Would it be possible to add a minor feature?

  • Add the restricted class to the <span.discourse-category-banners> or <div.category-title-header> element when the category is not public, the same way the category badge has.

It would be useful for tweaking the banner with an additional CSS to show the user that this category is special.

Right now, it is doable but complicated to select with CSS the lock icon and do some stuff, but since CSS doesnā€™t have parent selector, I can not use the presence of the lock icon to check if the banner should be modified.

I donā€™t really know how to do PRs yet, but would use this as a good reason to learn if youā€™d be up for my modification.

1 Like

Can this be made to work on tag-pages? I found the tag-banners plugin but it doesnā€™t have the ability to add text or links to it.