# 自定义主题：尽管系统中存在，\`categories.json\`中仍缺少类别

**URL:** https://meta.discourse.org/t/categories-missing-from-categories-json-despite-existing-in-the-system-custom-theme/365544
**Category:** Development
**Tags:** rest-api
**Created:** [2025年五月10日 00:50 UTC](https://meta.discourse.org/t/categories-missing-from-categories-json-despite-existing-in-the-system-custom-theme/365544 "2025-05-10T00:50:27Z")
**Posts on this page:** 1
**Showing post:** 1

<div class="post-metadata">

### Author: ![Steve\_John](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/steve_john/32/435022_2.png) [@Steve\_John](https://meta.discourse.org/u/Steve_John)
#### Post date: [2025年五月10日 00:50 UTC](https://meta.discourse.org/t/categories-missing-from-categories-json-despite-existing-in-the-system-custom-theme/365544/1 "2025-05-10T00:50:27Z")

</div>

我们构建了一个自定义的Discourse主题，通过JavaScript在主页上显示特定类别。该脚本使用预定义的类别名称列表（一组用逗号分隔的数组）来获取并渲染来自`/categories.json`的内容。

虽然大多数类别都正常显示，但仍有一些类别未出现在主页上——即使它们在脚本中明确列出且在系统中存在，具有有效的类别ID。

在检查`/categories.json`的响应后，我们发现这些特定类别根本未包含在API输出中。然而，它们都：

- 存在于Discourse实例中
- 是顶级类别
- 设置了`everyone`，至少具有“查看”权限
- 未归档、未隐藏或未嵌套

我们想了解：

1. Discourse在什么条件下会从`categories.json`中省略类别？
2. 如何确保所有需要的类别都出现在该响应中，特别是如果我们想通过自定义代码在首页显示它们？

任何见解或建议解决方案都将不胜感激。

---

_[View the full topic](https://meta.discourse.org/t/categories-missing-from-categories-json-despite-existing-in-the-system-custom-theme/365544)._
