# 使标签横幅也显示在被标记的主题页面上

**URL:** <https://meta.discourse.org/t/make-tag-banner-also-appear-on-tagged-topic-pages/395265>\
**Category:** Product Support\
**Tags:** tag-banners\
**Created:** [2026 年2 月 5 日 09:59 UTC](https://meta.discourse.org/t/make-tag-banner-also-appear-on-tagged-topic-pages/395265 "2026-02-05T09:59:18Z")\
**Posts on this page:** 1\
**Showing post:** 14

<div class="post-metadata">

作者： ![ToddZ](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/toddz/32/328350_2.png) [@ToddZ](https://meta.discourse.org/u/ToddZ)\
发布日期： [2026 年2 月 11 日 23:28 UTC](https://meta.discourse.org/t/make-tag-banner-also-appear-on-tagged-topic-pages/395265/14 "2026-02-11T23:28:52Z")

</div>

是的，我不知道它是否足够广泛有用，可以添加到原始插件中。一个单独的版本或一个名为“带标签的主题横幅”的附加组件可能更合适。

但我认为实用性相当有限，除非作者也能指定哪个标签是主要的。我想到的唯一方法是……

1. 一种黑客方法，比如让字母排序将像 `~` 这样的字符视为列表顶部。

> **AskBot 建议了一种用于插件猴子补丁的方法**
>
> ```ruby
> # plugin.rb
> after_initialize do
> module ::CustomTagSort
> def custom_tag_sort(tags)
> tags.sort_by do |tag|
> # 将以“~”开头的标签放在最前面，然后按 A-Z 排序
> [tag.name.start_with?("~") ? 0 : 1, tag.name.downcase]
> end
> end
> end
> 
> # 补丁到计算 visible_tags 或类似内容的序列化器/方法
> require_dependency 'topic_tags_mixin'
> TopicTagsMixin.prepend(Module.new do
> private
> 
> def all_tags
> return @tags if defined?(@tags)
> tags = topic.visible_tags(scope)
> if SiteSetting.tags_sort_alphabetically
> tags = ::CustomTagSort.custom_tag_sort(tags)
> else
> topic_count_column = Tag.topic_count_column(scope)
> tags = tags.sort_by { |tag| tag.public_send(topic_count_column) }.reverse
> end
> @tags = tags
> end
> end)
> end
> 
> ```

2.) 更好：根据指定的标签组顺序对标签进行排序。

搜索发现了很多要求对标签顺序进行更多控制的主题，因为这通常出于各种原因很重要（属 → 种，品牌 → 型号，等等）——但回复表明这需要相当大的工作量。

---

_[View the full topic](https://meta.discourse.org/t/make-tag-banner-also-appear-on-tagged-topic-pages/395265)._
