HRWiki:Counter: Difference between revisions
imported>HRWikiMirrorBot Reimported from hrwiki.org Wayback HTML→wikitext (full reconvert) |
imported>HRWikiMirrorBot Reimported from hrwiki.org Wayback HTML→wikitext (full reconvert) |
||
| Line 1: | Line 1: | ||
<!-- | <!-- Wayback HTML body (hrwiki.org); RawHtml --> | ||
== Usage == | <html> | ||
<a id="Usage" name="Usage"></a><h2> <span class="mw-headline">Usage</span></h2> | |||
<table border="1" style="border-collapse: collapse"> | |||
<tr> | |||
<td> <code>{{#count:</code><i>id</i><code>|</code><i>increment</i><code>}}</code> | |||
</td><td> Increments the counter <i>id</i> by <i>increment</i> and displays the result; <i>increment</i> can be omitted, and defaults to <code>1</code>. | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#resetcount:</code><i>id</i><code>|</code><i>value</i><code>|</code><i>increment</i><code>}}</code> | |||
</td><td> Silently sets the counter <i>id</i> to <i>value</i> minus <i>increment</i> (so that the next count by <i>increment</i> will display <i>value</i>); <i>value</i> and <i>increment</i> can be omitted, and both default to <code>1</code>. | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{<a href="/index.php?title=Template:hcount" title="Template:hcount">hcount</a>}}</code><br/><code>{{<a href="/index.php?title=Template:vcount" title="Template:vcount">vcount</a>}}</code> | |||
</td><td> Used in <a class="mw-redirect" href="/index.php?title=HRWiki:SORT" title="HRWiki:SORT">sortable tables</a>. <i>See <a href="#Sortable_Tables" title="">below</a>.</i> | |||
</td></tr></table> | |||
<a id="Examples" name="Examples"></a><h2> <span class="mw-headline">Examples</span></h2> | |||
<p><b>count</b> is a <a class="extiw" href="/index.php?title=Help:Parser_function" title="meta:Help:Parser function">parser function</a> that returns an integer that increments each time the function is called: | |||
</p> | |||
<table border="1" style="border-collapse: collapse"> | |||
<tr style="background: #EEE"> | |||
<th> Code </th><th> Gives | |||
</th></tr> | |||
<tr> | |||
<td> <code>{{#count:basic}}</code> </td><td> 1 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:basic}}</code> </td><td> 2 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:basic}}</code> </td><td> 3 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:basic}}</code> </td><td> 4 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:basic}}</code> </td><td> 5 | |||
</td></tr></table> | |||
<p>The counters can be given different names, so you can have more than one of them on the same page:<br/> | |||
<small>(The actual name doesn't matter, so long as they're different. If you use a counter in a template, pick a name that'll be unique.)</small> | |||
</p> | |||
<table border="1" style="border-collapse: collapse"> | |||
<tr style="background: #EEE"> | |||
<th> Code </th><th> Gives | |||
</th></tr> | |||
<tr> | |||
<td> <code>{{#count:first}}</code> </td><td> 1 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:second}}</code> </td><td> 1 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:second}}</code> </td><td> 2 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:second}}</code> </td><td> 3 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:first}}</code> </td><td> 2 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:second}}</code> </td><td> 4 | |||
</td></tr></table> | |||
<p>You can also make the counter count by twos, or by any other number: | |||
</p> | |||
<table border="1" style="border-collapse: collapse"> | |||
<tr style="background: #EEE"> | |||
<th> Code </th><th> Gives | |||
</th></tr> | |||
<tr> | |||
<td> <code>{{#count:evens|2}}</code> </td><td> 2 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:evens|2}}</code> </td><td> 4 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:evens|2}}</code> </td><td> 6 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:evens|2}}</code> </td><td> 8 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:evens|2}}</code> </td><td> 10 | |||
</td></tr></table> | |||
<p>Different increments can be used at different times, depending on what is needed: | |||
</p> | |||
<table border="1" style="border-collapse: collapse"> | |||
<tr style="background: #EEE"> | |||
<th> Code </th><th> Gives | |||
</th></tr> | |||
<tr> | |||
<td> <code>{{#count:strange|1}}</code> </td><td> 1 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:strange|1}}</code> </td><td> 2 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:strange|3}}</code> </td><td> 5 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:strange|0}}</code> </td><td> 5 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:strange|-1}}</code> </td><td> 4 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:strange|2}}</code> </td><td> 6 | |||
</td></tr></table> | |||
<p>The counter can be reset partway through a page: | |||
</p> | |||
<table border="1" style="border-collapse: collapse"> | |||
<tr style="background: #EEE"> | |||
<th> Code </th><th> Gives | |||
</th></tr> | |||
<tr> | |||
<td> <code>{{#count:basic}}</code> </td><td> 1 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:basic}}</code> </td><td> 2 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:basic}}</code> </td><td> 3 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#resetcount:basic}}</code> </td><td> | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:basic}}</code> </td><td> 1 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:basic}}</code> </td><td> 2 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:basic}}</code> </td><td> 3 | |||
</td></tr></table> | |||
<p>You can also set what number you want to start on: | |||
</p> | |||
<table border="1" style="border-collapse: collapse"> | |||
<tr style="background: #EEE"> | |||
<th> Code </th><th> Gives | |||
</th></tr> | |||
<tr> | |||
<td> <code>{{#resetcount:starting|11}}</code> </td><td> | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:starting}}</code> </td><td> 11 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:starting}}</code> </td><td> 12 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:starting}}</code> </td><td> 13 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:starting}}</code> </td><td> 14 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:starting}}</code> </td><td> 15 | |||
</td></tr></table> | |||
<p>If you're using an increment, you need to give it to <code>#resetcount</code> too: | |||
</p> | |||
<table border="1" style="border-collapse: collapse"> | |||
<tr style="background: #EEE"> | |||
<th> Code </th><th> Gives | |||
</th></tr> | |||
<tr> | |||
<td> <code>{{#resetcount:starting evens|14|2}}</code> </td><td> | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:starting evens|2}}</code> </td><td> 14 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:starting evens|2}}</code> </td><td> 16 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:starting evens|2}}</code> </td><td> 18 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:starting evens|2}}</code> </td><td> 20 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:starting evens|2}}</code> </td><td> 22 | |||
</td></tr></table> | |||
<p>Use a negative increment to count down. As noted above, be sure to pass the increment to <code>#resetcount</code> too: | |||
</p> | |||
<table border="1" style="border-collapse: collapse"> | |||
<tr style="background: #EEE"> | |||
<th> Code </th><th> Gives | |||
</th></tr> | |||
<tr> | |||
<td> <code>{{#resetcount:countdown|3|-1}}</code> </td><td> | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:countdown|-1}}</code> </td><td> 3 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:countdown|-1}}</code> </td><td> 2 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:countdown|-1}}</code> </td><td> 1 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:countdown|-1}}</code> </td><td> 0 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#count:countdown|-1}}</code> </td><td> -1 | |||
</td></tr></table> | |||
<p>You can use the counter in other <a class="extiw" href="/index.php?title=ParserFunctions" title="meta:ParserFunctions">parser functions</a>: | |||
</p> | |||
<table border="1" style="border-collapse: collapse"> | |||
<tr style="background: #EEE"> | |||
<th> Code </th><th> Gives | |||
</th></tr> | |||
<tr> | |||
<td> <code>{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}}</code> </td><td> odd | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}}</code> </td><td> even | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}}</code> </td><td> odd | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}}</code> </td><td> even | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}}</code> </td><td> odd | |||
</td></tr></table> | |||
<table border="1" style="border-collapse: collapse; margin-top: 1em"> | |||
<tr style="background: #EEE"> | |||
<th> Code </th><th> Gives | |||
</th></tr> | |||
<tr> | |||
<td> <code>{{#expr:{{#count:squares}} * {{#count:squares|0}}}}</code> </td><td> 1 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#expr:{{#count:squares}} * {{#count:squares|0}}}}</code> </td><td> 4 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#expr:{{#count:squares}} * {{#count:squares|0}}}}</code> </td><td> 9 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#expr:{{#count:squares}} * {{#count:squares|0}}}}</code> </td><td> 16 | |||
</td></tr> | |||
<tr> | |||
<td> <code>{{#expr:{{#count:squares}} * {{#count:squares|0}}}}</code> </td><td> 25 | |||
</td></tr></table> | |||
<a id="Sortable_Tables" name="Sortable_Tables"></a><h2> <span class="mw-headline">Sortable Tables</span></h2> | |||
<p>When using count in <a class="mw-redirect" href="/index.php?title=HRWiki:SORT" title="HRWiki:SORT">sortable tables</a>, please use the {{<a href="/index.php?title=Template:hcount" title="Template:hcount">hcount</a>}} and {{<a href="/index.php?title=Template:vcount" title="Template:vcount">vcount</a>}} templates. Be sure to carefully read their documentation in order to sort table entries correctly. | |||
</p> | |||
<div class="visualClear"></div> | |||
</html> | |||
Latest revision as of 21:00, 18 July 2026
Usage
{{#count:id|increment}}
| Increments the counter id by increment and displays the result; increment can be omitted, and defaults to 1.
|
{{#resetcount:id|value|increment}}
| Silently sets the counter id to value minus increment (so that the next count by increment will display value); value and increment can be omitted, and both default to 1.
|
{{hcount}}{{vcount}}
| Used in sortable tables. See below. |
Examples
count is a parser function that returns an integer that increments each time the function is called:
| Code | Gives |
|---|---|
{{#count:basic}} | 1 |
{{#count:basic}} | 2 |
{{#count:basic}} | 3 |
{{#count:basic}} | 4 |
{{#count:basic}} | 5 |
The counters can be given different names, so you can have more than one of them on the same page:
(The actual name doesn't matter, so long as they're different. If you use a counter in a template, pick a name that'll be unique.)
| Code | Gives |
|---|---|
{{#count:first}} | 1 |
{{#count:second}} | 1 |
{{#count:second}} | 2 |
{{#count:second}} | 3 |
{{#count:first}} | 2 |
{{#count:second}} | 4 |
You can also make the counter count by twos, or by any other number:
| Code | Gives |
|---|---|
{{#count:evens|2}} | 2 |
{{#count:evens|2}} | 4 |
{{#count:evens|2}} | 6 |
{{#count:evens|2}} | 8 |
{{#count:evens|2}} | 10 |
Different increments can be used at different times, depending on what is needed:
| Code | Gives |
|---|---|
{{#count:strange|1}} | 1 |
{{#count:strange|1}} | 2 |
{{#count:strange|3}} | 5 |
{{#count:strange|0}} | 5 |
{{#count:strange|-1}} | 4 |
{{#count:strange|2}} | 6 |
The counter can be reset partway through a page:
| Code | Gives |
|---|---|
{{#count:basic}} | 1 |
{{#count:basic}} | 2 |
{{#count:basic}} | 3 |
{{#resetcount:basic}} | |
{{#count:basic}} | 1 |
{{#count:basic}} | 2 |
{{#count:basic}} | 3 |
You can also set what number you want to start on:
| Code | Gives |
|---|---|
{{#resetcount:starting|11}} | |
{{#count:starting}} | 11 |
{{#count:starting}} | 12 |
{{#count:starting}} | 13 |
{{#count:starting}} | 14 |
{{#count:starting}} | 15 |
If you're using an increment, you need to give it to #resetcount too:
| Code | Gives |
|---|---|
{{#resetcount:starting evens|14|2}} | |
{{#count:starting evens|2}} | 14 |
{{#count:starting evens|2}} | 16 |
{{#count:starting evens|2}} | 18 |
{{#count:starting evens|2}} | 20 |
{{#count:starting evens|2}} | 22 |
Use a negative increment to count down. As noted above, be sure to pass the increment to #resetcount too:
| Code | Gives |
|---|---|
{{#resetcount:countdown|3|-1}} | |
{{#count:countdown|-1}} | 3 |
{{#count:countdown|-1}} | 2 |
{{#count:countdown|-1}} | 1 |
{{#count:countdown|-1}} | 0 |
{{#count:countdown|-1}} | -1 |
You can use the counter in other parser functions:
| Code | Gives |
|---|---|
{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} | odd |
{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} | even |
{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} | odd |
{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} | even |
{{#ifexpr:{{#count:alternate}} mod 2 = 0|even|odd}} | odd |
| Code | Gives |
|---|---|
{{#expr:{{#count:squares}} * {{#count:squares|0}}}} | 1 |
{{#expr:{{#count:squares}} * {{#count:squares|0}}}} | 4 |
{{#expr:{{#count:squares}} * {{#count:squares|0}}}} | 9 |
{{#expr:{{#count:squares}} * {{#count:squares|0}}}} | 16 |
{{#expr:{{#count:squares}} * {{#count:squares|0}}}} | 25 |
Sortable Tables
When using count in sortable tables, please use the {{hcount}} and {{vcount}} templates. Be sure to carefully read their documentation in order to sort table entries correctly.