How to get the latest topics list from a plugin

Hello everyone,

I am editing a Discourse, and I have not found what I want to do by default. I wish that on the home page, the categories are in a first block (full width) then below, the list (detailed) of the last subjects is displayed.
The different layout options do not allow this. The closest option displays the categories on the left, and the last topics (light) on the right.

The Revolut community offers a display like this: https://community.revolut.com/ but they are only changed to CSS the two-column view to put it in two row.

To answer my need, I realized that I could simply display the categories with the default layout, and create a plugin that hangs on ā€œdiscovery-belowā€.

Unfortunately, I do not see how to get the list of recent topics to assign to my template in my plugin.

Do you have any ideas to guide me in my development?

Thank you

OK

A good strategy with all modifcations is do the minimum needed: find something that exists that is closest and modify that. This is not just because we are all inherently lazy as programmers, but because you want to have the minimum exposure to risk wrt changes to the core code so your functionality has the best chance of survival with minimal changes going forward.

I hope Iā€™ve understood your requirement correctly. In any case here goes:

I canā€™t go into huge detail here (as need to put dinner on the table tonight), but hereā€™s the strategy I would employ here:

  1. Note the closest data arrangement to what I think you need is ā€˜Boxes with Featured Topicsā€™. When you simply render the /categories.json in this mode you will note the data comes back in a way that is close to what you might need, that is Categories with short nested lists of topics for each Category - handy!

  2. Consider changing the featured topics method in the ruby controller to spit back the latest topics (or whatever) instead of ā€˜featuredā€™: https://github.com/discourse/discourse/blob/master/app/models/category_featured_topic.rb

  3. Override the template(s) for this mode to rearrange the elements in the way that you prefer. Iā€™d take a look at this template to start with: https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/components/categories-boxes-with-topics.hbs

NB One thing to be wary of is why things are like they are already. The Category Boxes layout is designed to give you a quick view of as many Categories on the same page as possible. Having it all going linearly down the page instead may undesirably push some Categories off screen

One compromise is to just do part 2 only with no layout changes - an added bonus being itā€™s quicker and itā€™s less risky.

Thatā€™s how Iā€™d start to go about this ā€¦ you may find your strategy needs modification as you work through it.

Hope thatā€™s helpful and gets you going. Sorry I canā€™t spend significant time on it at present.

2 Likes