FANDOM


I’m lazy. All work I do, I do to reduce the amount of work needing to be done later.

Do you hate manually adding categories to your articles? Do you dislike even bothering with categories at all, but still need them to organize your pages? Sit down, then, because with a bit of work you can make such tasks a thing of the past.

MediaWiki software has tons of intuitive functions built in to every Wikia that you can use to program your templates to do everything for you. We will look specifically at how they can be used with your templates to make them categorize pages for you.

Step 1 — Select your template

The best templates for this are templates that are used on many pages & have many parameters; Infoboxes typically. For example, if you have an Infobox that is used on all pages that are “tanks,” & you are trying to organize tank pages by their rank, then that template is the one you will want to use. Template:MYTEMPLATENAME on your Wikia will be the location of the template you have selected.

Step 2 — Identify which parameter should dictate the category

For example, on this page’s infobox, tier = 3; this means tier is the parameter we want, since we are trying to organize pages by rank. The Categories we are working with are Tier 2 Tanks, Tier 3 Tanks, & Tier 4 Tanks. We want the Infobox on this page to automatically categorize the page into one of those categories based on what tier has been specified. This is just an example; the parameter could be anything, & you can figure out the parameter you want from a given template in the following ways:

Step 3 — Code

In the Infobox code, we will add something called a switch function. Here is a simple example:

<includeonly>
{{#switch: {{{tier}}}
    | 2  = [[Category:Tier 2 Tanks]]
    | 3  = [[Category:Tier 3 Tanks]]
    | 4  = [[Category:Tier 4 Tanks]]
}}
</includeonly>

Add that to the very bottom of your chosen template. {{{}}} signifies a template parameter. If the parameter you are targeting is tier, then {{{tier}}} will tell the #switch to do different things when different values are inserted in the tier parameter on the page itself. If, on the page itself, a user sets the tier to 3, then since 3 = [[Category:Tier 3 Tanks]] in our switch function, the template will add the Tier 3 Tanks Category to the page! You can add totally different things to the #switch as well, such as this example:

<includeonly>
{{#switch: {{{hair color}}}
    | Brown   = [[Category:Characters with brown hair]]
    | Blonde  = [[Category:Characters with blonde hair]]
}}
</includeonly>

Advanced

Parser functions such as #switch are very versatile, & if you throw in some magic words, you can get even more specific functionality.

For example, #switch is normally case sensitive (to some degree), so if you use red in the template switch function, & you use color = Red on a page, the template will fail to categorize the page properly. But you can teach it to ignore that using this code:

<includeonly>
{{#switch: {{lc:{{{color}}}}}
    | red   = [[Category:Red]]
    | blue  = [[Category:Blue]]
}}
</includeonly>

Since the {{lc:}} magic word transforms anything within it to lowercase, you can insert any kind of capitalization into a parameter & it will not matter; it will always be lowercase. For example, if you specify Red, RED, or rEd as the value on a page, the template will always interpret it as red because {{lc:}} makes it lowercase, so since the value matches red as specified in the #switch, it will work regardless of capitalization.

This is just one application of a single magic word; there are dozens of magic words with numerous applications, so the opportunities are nearly limitless.

Next Steps

Try this out for yourself. If you were able to apply this principle properly, then you can rinse & repeat until every page on your Wikia contains a template that automatically categorizes it. You can do this for multiple parameters in a given template as well.

Once implemented, the end result is a system of templates that handles all of your categories for you. As an admin, you will never have to worry about fixing, rearranging, or adding categories to pages ever again, since the templates will automatically change their categories based on the information your users add to each page.

It is a bit of work, to be sure, but it could drastically reduce (if not totally eliminate) the amount of work needing to be done later.

Source Editor is highly recommended for this topic.
Switch editors today.