在分类列表中显示主题数

Currently the forum shows the number of posts per month. Is there a way to always show the total number of topics?
I saw this post which seems to ask exactly what I’m looking for, but it looks like there is no answer:

3 个赞

It isn’t shown anywhere in the UI but if you need to know the numbers, you can try this Data Explorer query:

1 个赞

你好,
1)我想在类别导航中显示主题计数。
但是有些类别不显示主题计数。我查看了类别配置,但没有看到任何说需要启用它的设置。
2)另外,在侧边栏导航区域,我们可以为每个类别显示主题计数吗?

有一个用户设置“显示新项目计数”

https://meta.discourse.org/my/preferences/navigation-menu

您可以使用默认侧边栏“显示新项目计数”管理员设置来更改默认值。更改后,您可以选择也为现有用户更改它。

但是我的意思是显示一个类别中的总主题数。
父类别和子类别的总主题数将显示在下拉导航菜单中。

<script type="text/x-handlebars" data-template-name="components/parent-category-row">
  <!-- ... -->
  <td class="topics">
    主题: ({{this.category.totalTopicCount}})
  </td>

  <td class="replies">
    回复: ({{this.category.totalReplyCount}})
  </td>

  <!-- ... -->
</script>

我认为类似这样的东西应该可以工作。

如何运行此代码?
创建主题组件?

您好,抱歉错过了。试试这个 CSS。

要在 Discourse 中创建显示子类别主题计数的 CSS,您需要定位 Discourse DOM 中代表子类别主题计数的特定元素。下面是一个 CSS 示例,您可以通过 Discourse 中的管理员界面应用它。

  1. 导航到“管理员自定义”部分

    • 转到 Admin > Customize > Themes
    • 选择一个现有主题或创建一个新主题。
    • 点击 Edit CSS/HTML
  2. 添加自定义 CSS

    • CSS 选项卡中,添加您的自定义样式。例如:
/* Custom CSS to show topic count in subcategory */
.subcategory {
    position: relative;
    padding-right: 40px; /* Adjust as needed for spacing */
}

.subcategory .subcategory-details .topics {
    font-size: 0.8em; /* Makes the topic count slightly smaller */
    color: #666; /* Use a color that matches your theme */
    position: absolute;
    top: 50%;
    right: 10px; /* Place it on the right of the subcategory */
    transform: translateY(-50%);
    background: #f2f2f2; /* Background color to make it stand out */
    padding: 2px 5px;
    border-radius: 3px; /* Rounded corners for a better look */
}

.subcategory:hover .subcategory-details .topics {
    background: #ddd; /* Change background color on hover, if desired */
}
  1. 保存更改
    • 点击 Save 按钮应用自定义 CSS。

上面的 CSS 假定 Discourse 中子类别的现有结构。您可能需要使用浏览器开发者工具(在大多数浏览器中右键单击并选择“检查”)来检查 HTML 结构,并根据您的 Discourse 设置的实际 DOM 结构修改 CSS 选择器。

在 Discourse 中,子类别通常具有 .subcategory 类,而主题计数可能位于某些元素结构中,您可以使用更具体的 CSS 来定位它们(如果需要)。确保 .topics.subcategory-details 等元素及其层级结构与您的平台中的结构匹配,以实现准确的样式设置。

1 个赞

感谢您的支持,但它没有效果