Get latest topic of a subcategory

AI-generated summary

The discussion revolves around getting the latest topic of a subcategory in Discourse. Antichrist is trying to achieve this but is unable to use category.latestTopic for subcategories. awesomerobot suggests treating subcategories the same as parent categories, but Antichrist explains that this does not work. awesomerobot clarifies that topics for subcategories are not included on the category page, making it impossible to use latestTopic. A plugin modification may be required, but Antichrist is seeking help as they lack the necessary experience with Discourse, Ruby, and plugin development.

Is there a method to get the latest topic of a subcategory that I receive in category.subcategories? I can use category.latestTopic to get the latest topic of the main category but I can’t use it for subcategories, any smart workaround for this? I would like to show the latest topic of a subcategory when i list the subcategories.

I’m not 100% sure of the context (can you post your code?) but I think you should be able to treat subcategories the same as parent categories.

So category.latestTopic would work the same for any category/subcategory. If you loop through each of the subcategories using category.subcategories you should be able to use category.latestTopic within that loop.

Hello, sadly it does not. behave the same way.
Inside:

<script type="text/x-handlebars" data-template-name="components/categories-only">
....
    {{#each categories as |c|}}
...

I can use c.latestTopic
But inside after the above:

...
  {{#each c.subcategories as |s|}}
...

I can’t use s.latestTopic It doesn’t return anything

Ohh I see now, thanks for the additional detail. It looks like we don’t include topics for subcategories on the category page at all, so using latestTopic definitely isn’t possible… I think the serializer would need to be modified in a plugin to accomplish this? (sorry, I’m not sure of the specifics for accomplishing that).

I don’t know, sadly I’m not that experienced with Discourse or Ruby or whatever part has to be modified.
I hope someone can come up with a solution, I’ve been trying this for days and weeks by now.