I make changes in discourse application where I want to show to topics according to number of replies, I created rails query but I am no able to find out the view part, Where I need to show and adding this scope.
סיכום מבוסס בינה מלאכותית
kapil65 wants to sort topics by number of replies in a specific category and display them on the homepage, but is unsure where to place the backend query or which view file renders the featured topics. pfaffman suggests using plugins or themes for customizations. kapil65 clarifies they don’t want to create a plugin, just modify backend queries. simon advises using the existing “Topic List Sort By” category setting and warns against modifying core code, recommending plugins instead. kapil65 acknowledges the advice. In post 6, kapil65 reiterates the need to sort right-side topic links by reply count, confirming backend changes are needed. simon explains that changing the category setting may require manually breaking the cache via the Rails console using CategoryFeaturedTopic.feature_topics_for(c) to force the homepage to reflect the new sort order, noting the cache may also expire naturally within 24 hours. kapil65 confirms they ran the query but still can’t locate the view file or model where the featured topics are rendered, seeking guidance on where to insert their custom query.
If you want to change how Discourse behaves, you’ll need to see Developing Discourse Plugins - Part 1 - Create a basic plugin or perhaps Beginner’s guide to developing Discourse Themes.
I don’t want to create new plugin, I just want to change the category & topic queries from backend side and want to show on view, but Can’t find out where the list of topics link are shown.
Okay Simon, Thank you
I think It will help me out
I don’t think you need to modify code for this, but you may need to run a command from your site’s rails console to get the topics to display in the new order on your site’s homepage.
When you select “Categories with Featured Topics” for the desktop category page style site setting, the order that the featured topics are displayed in should be set by the value of each category’s “Topic List Sort By” setting. Unfortunately, if you make a change to a category’s “Topic List Sort By” setting, that change is not immediately shown on the site’s homepage. I am not sure where Discourse is caching the featured topics that are displayed on the home or what action is used by Discourse to trigger breaking the cache.
From testing on my own site, I see that the cache can be broken by running the following from the rails console:
# Assign the category you want to fix the results for to a variable, for example:
c = Category.find(42)
# Then run
CategoryFeaturedTopic.feature_topics_for(c)
After running that, the topics should get displayed on the homepage in the order you selected for the category’s “Topic List Sort By” setting. I don’t think that running that command can cause any issues, but always be careful running commands from the rails console.
I’m sure there is an easier way to do this. Possibly you just need to wait for up to 24 hours for Discourse to break the cache on the old featured topic list. I’m not seeing where in the code the cache is broken. The relevant code seems to be here: discourse/app/models/category_featured_topic.rb at main · discourse/discourse · GitHub.
I hit that query but main problem is that where this featured topics are displayed on the home, on which .html file have code to shown this data on UI.
I already made a queries for what data I need to sort but problem is where I put the query into which model.

