Module:SongCategories
Appearance
| This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
| This Lua module is used on many pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
This module is used by the {{Infobox song}} template to assign categories based on the |type= parameter. It processes the song type and adds appropriate categories to articles.
Usage
The module is invoked within the {{Infobox song}} template as follows:
{{#invoke:SongCategories|getCategories|type={{{type|}}}}}
The module expects a type parameter with one of the following values:
Top 10 Hit Song: Adds [[Category:Top 10 Hit songs]].No.1 Hit Song: Adds [[Category:Number One Songs]].Major Hit Song: Adds [[Category:Major Hit Songs]] and [[Category:Number One Songs]].- Any other value or empty input: No categories are added.
Example
In an article using the {{Infobox song}} template:
{{Infobox song
| name = Example Song
| type = Major Hit Song
| artist = Example Artist
| album = Example Album
| released = January 1, 2020
| genre = Pop
| rating = 4
}}
This will add the article to [[Category:Major Hit Songs]] and [[Category:Number One Songs]].
Notes
- The module is case-sensitive. Ensure the
typeparameter matches the exact values (Top 10 Hit Song,No.1 Hit Song,Major Hit Song). - If you need case-insensitive matching, the module can be modified to normalize the input (e.g., convert to lowercase).
- Ensure the categories ([[Category:Top 10 Hit songs]], [[Category:Number One Songs]], [[Category:Major Hit Songs]]) exist on the wiki to avoid redlinks.
See also
- {{Infobox song}} – The template that uses this module.
- Module:SongCertifications – Handles certification-based categories for the same template.
local p = {}
function p.getCategories(frame)
local songType = frame.args['type'] or ''
local categories = {}
if songType == 'Top 10 Hit Song' then
table.insert(categories, '[[Category:Top 10 Hit Songs]]')
elseif songType == 'No.1 Hit Song' then
table.insert(categories, '[[Category:Number One Songs]]')
elseif songType == 'Major Hit Song' then
table.insert(categories, '[[Category:Major hit songs]]')
table.insert(categories, '[[Category:Number One Songs]]')
end
return table.concat(categories, '')
end
return p