# 我如何在手机上查看分类和“最新”？

**URL:** <https://meta.discourse.org/t/how-can-i-view-categories-and-latest-on-mobile/358489>\
**Category:** Support\
**Created:** [2025年三月23日 12:28 UTC](https://meta.discourse.org/t/how-can-i-view-categories-and-latest-on-mobile/358489 "2025-03-23T12:28:59Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![Arkshine](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/arkshine/32/298682_2.png) [@Arkshine](https://meta.discourse.org/u/Arkshine)\
**Post date:** [2025年三月23日 18:05 UTC](https://meta.discourse.org/t/how-can-i-view-categories-and-latest-on-mobile/358489/3 "2025-03-23T18:05:39Z")

</div>

我看了，他们使用了一些自定义 JS 代码来强制显示“类别和最新主题”视图。

我没有检查是否有更好的方法；这是他们所做的（我已将代码现代化并添加了一些注释）：

```js
import { apiInitializer } from "discourse/lib/api";
import CategoriesAndLatestTopics from "discourse/components/categories-and-latest-topics";
import CategoryList from "discourse/models/category-list";
import { MAX_UNOPTIMIZED_CATEGORIES } from "discourse/lib/constants";

export default apiInitializer((api) => {
  // 强制显示“类别和最新主题”视图。
  api.modifyClass(
    "component:discovery/categories-display",
    (Superclass) =>
      class extends Superclass {
        get categoriesComponent() {
          if (this.args.parentCategory) {
            return super.categoriesComponent;
          } else {
            return CategoriesAndLatestTopics;
          }
        }
      }
  );

  // 与原始代码相同，只是修改了“this.site.desktopView”检查，
  // 因此它也能为移动设备找到最新主题。
  api.modifyClass(
    "route:discovery-categories",
    (Superclass) =>
      class extends Superclass {
        async findCategories(parentCategory) {
          let model;

          let style = this.siteSettings.desktop_category_page_style;
          if (this.site.categories.length > MAX_UNOPTIMIZED_CATEGORIES) {
            style = "categories_only";
          }

          if (
            style === "categories_and_latest_topics" ||
            style === "categories_and_latest_topics_created_date"
          ) {
            model = await this._findCategoriesAndTopics(
              "latest",
              parentCategory
            );
          } else if (style === "categories_and_top_topics") {
            model = await this._findCategoriesAndTopics(
              "top",
              parentCategory
            );
          } else {
            PreloadStore.remove("topic_list");
            model = await CategoryList.list(this.store, parentCategory);
          }

          return model;
        }
      }
  );
});

```

您可以尝试将代码粘贴到新的组件 → 编辑代码 → JS 选项卡中。  
如果有效，请告诉我。

---

_[View the full topic](https://meta.discourse.org/t/how-can-i-view-categories-and-latest-on-mobile/358489)._
