diff --git a/config/locales/server.en.yml b/config/locales/server.en.yml index 42dd45ca2..9a5725303 100644 --- a/config/locales/server.en.yml +++ b/config/locales/server.en.yml @@ -765,6 +765,7 @@ en: max_private_messages_per_day: "The maximum amount of private messages users can create per day" suggested_topics: "Number of suggested topics shown at the bottom of a topic" + limit_suggested_to_category: "Only show topics from the current category in suggested topics" clean_up_uploads: "Remove orphaned uploads to prevent illegal hosting. WARNING: you might want to make a backup of your /uploads directory before enabled this setting." clean_orphan_uploads_grace_period_hours: "Grace period (in hours) before an orphan upload is removed." diff --git a/config/site_settings.yml b/config/site_settings.yml index 098af1310..76afe4d59 100644 --- a/config/site_settings.yml +++ b/config/site_settings.yml @@ -34,6 +34,9 @@ basic: suggested_topics: client: true default: 5 + limit_suggested_to_category: + client: false + default: false default_external_links_in_new_tab: false track_external_right_clicks: client: true diff --git a/lib/suggested_topics_builder.rb b/lib/suggested_topics_builder.rb index bd4c3e54c..3051fdf34 100644 --- a/lib/suggested_topics_builder.rb +++ b/lib/suggested_topics_builder.rb @@ -20,8 +20,13 @@ class SuggestedTopicsBuilder # Only add results if we don't have those topic ids already results = results.where('topics.id NOT IN (?)', @excluded_topic_ids) .where(visible: true) - .to_a - .reject { |topic| @category_topic_ids.include?(topic.id) } + + # If limit suggested to category is enabled, restrict to that category + if @category_id && SiteSetting.limit_suggested_to_category? + results = results.where(category_id: @category_id) + end + + results = results.to_a.reject { |topic| @category_topic_ids.include?(topic.id) } unless results.empty? # Keep track of the ids we've added