创建子主题?

I would like to make some topics sub-topics of others.

Say I have “Topic A”. On the Topic A page, I will put a button to “create sub topic”. That will allow the user to create a new topic, “topic b”. topic b would be a child of Topic A.

What this means, from the user experience, is:

I could also have a button on the Topic A page to “view all the child topics of Topic A”, and this would go to a list of Topic A’s child topics, such as topic b and any other topics that are children of Topic A.

What’s the best way to do this? (I’m assuming I’ll have to do it in a plugin, which is fine.)

Note I’d only be looking for one level of subtopic down, not several.

Here’s some detail on the possibilities I think could do it:

Categories (though this probably is not the best way to go)

Categories would provide similar functionality to what I have in mind, but that could get too heavy once there are a decent number of topics with subtopics (it seems like overkill to basically have a new category for each parent topic).

or

Tags

The best I can think of right now is using tagging. So that when you click “create sub topic” on Topic A, it opens up a new topic, and I programmatically add a hidden tag, like “Topic-A”, that links to Topic A. Then when you click “view all sub topics” of Topic A, it does a search for the tag “Topic-A”.

This seems pretty clean, other than the fact that there will be a lot of tags (basically one tag for each main topic, which could end up being a lot).

or

Custom Fields for Topics

Another possibility I’ve considered is to create a custom field for topics, which would be an array of the ids of that topic’s sub-topics. This also could work, but would probably be slightly more complicated to code.

For example, I’d have to update the main topic’s custom field only after a subtopic is created; and, I’d have to create a new kind of search–searching for all the topics within the main topic’s custom field array–instead of just using the pre-built tag search functionality.

Is there another solution I’m missing?

2 个赞

我看到另一个可能可行的解决方案,无需大量代码工作。

通过 自定义向导插件,您可以在一个流程中执行多个操作。在这种情况下,您可以让用户通过向导输入其子主题,该向导将:

  • 为子主题创建一个新话题
  • 在主话题中创建一个回复并链接到该子主题

通过为所有主帖添加一些自定义 CSS(您可以添加一个 CSS 类,以便通过分类或标签进行选择),您可以修改回复的外观以符合您的设想。您也可能通过向导找到一种方法,为回复添加一个参数,从而让您仅筛选出自动回复。

如果您不喜欢回复方案,我认为自定义向导也可以为创建好的子主题添加标签。

1 个赞

我没想到这一点。谢谢。我目前缺失的关键部分,是在子主题中包含一个能链接回主主题的元素,例如与子主题关联的标签(如“Topic-A”)。

您是否认为,向导在提交时,会通过 API 调用创建该标签并将其与子主题关联?(我对向导插件不太熟悉。)

此外,我认为向导插件的一个局限在于,它会打开一个独立的页面,该页面没有我网站的常规页眉——换句话说,我认为任何包含向导的页面,其外观都会与应用的其余部分大不相同,这在这种情况下可能会让用户感到困惑。

我也在想,我希望有一个级别的子主题。这可以实现一个级别的嵌套/层次结构,同时保持界面整洁,避免出现大量嵌套对话。

我可能会这样使用它:

  • 为一个剧集/帖子/文章创建一个主题,然后让人们根据他们的反应创建子主题。

  • 创建一个问题主题,然后让人们创建包含他们自己答案的子主题(如果可以选择限制每人一个子主题,那就更好了)。

您在创建插件或利用当前 Discourse 功能实现这一点方面有进展吗?

我唯一能想到的方法是使用主题自定义字段。例如,子主题可以有一个链接回主主题的自定义字段。然后,您可以搜索所有以该主主题作为自定义字段值的ョピック。我还没有完全实现的插件,但我能够使用我在这里提到的代码在开发中基本实现它:Retrieve Topics based on custom field? - #12 by JQ331

1 个赞

是的,我想象一下,如果我们创建一个名为“topic-parent”或类似的自定义主题字段,那么将有很多方法可以利用它。我会更深入地研究您分享的链接,并希望在此过程中学习一些 Ruby。谢谢!

1 个赞