Plurality Checker

By Timothy FosterTimothy Foster

and James KanjoJames Kanjo (for improving it).


One of those pestering little problems with ListPages is the idea that when using some of the variables like %%comments%% along with its respective word like "comments", the word doesn't automatically flip from singular to plural when it goes from one comment to two comments.

For instance, let us say you have this code:

[[module ListPages ...]]
%%comments%% Comments

Even if the page only has one comment, you get the annoying "1 Comments". A small problem, but also a bit of a thorn in the side.

This little snippet and CSI will enable you to easily cause the word to automatically switch from singular to plural depending on the variable's value!


Attribute Required? Allowed Values Default Description
variable Yes A ListPages variable with a numeric output, such as %%comments%% none This is the variable you want to be analyzed for plurality
singular Yes The singular form of a word none This is the word for singularity or plurality to be applied to.
plural No The plural form of the word none This is only necessary for irregular English words like "person/people" or "city/cities" as opposed to "comment/comments" or "revision/revisions"

Note that for this to work, you must define two separate includes:

The following goes on the bottom of the entire page:

[[include :snippets:sp-css]]

This code is used every time you need the plurality check. This is described further below:

[[include :snippets:sp |variable= |singular= ]]


This code shows the source for the below example.

[[module ListPages category="code" limit="1"]]
[[include :snippets:sp |variable=%%total_or_limit%% |singular=page]]
[[include :snippets:sp |variable=%%total_or_limit%% |singular=person |plural=people]]
[[module ListPages category="code" limit="2"]]
[[include :snippets:sp |variable=%%total_or_limit%% |singular=page]]
[[include :snippets:sp |variable=%%total_or_limit%% |singular=person |plural=people]]

[[include :snippets:sp-css]]

In action

1 pages
1 personpeople

2 pages
2 personpeople

2 pages
2 personpeople


You can also use this code inline with a few extra characters:

[[module ListPages category="code" limit="1"]]
Currently, \
[[include :snippets:sp |variable=%%total_or_limit%% |singular=page is |plural=pages are]]
[!----] being displayed.

Which produces:

Currently, 1 page ispages are being displayed.

If you place the following CSS code in your master CSS, then you should never need to use the sp-css include (the one that would normally go on the bottom of the page):

@import url(;

Thanks to tsangk for this great snippet: conditional-blocks

text above inserted with:

[[include :snippets:if START |unique=1|type=equal|var1=%%name%%|var2=conditional-blocks]]
**##red|Thanks to tsangk for this great snippet:##** [[[code:conditional-blocks]]]
[[include :snippets:if END]]

Other snippets posted by Timothy Foster

Fancy HR Dividers - 07 Apr 2021 06:23
Carousel - 24 May 2015 01:18
Modal Image - 01 May 2015 17:20
Bootstrap Image Box - 19 Jul 2014 01:27
Togglecheck - 17 Dec 2013 20:27
Alternative Specific Users Only - 11 Dec 2013 18:04
Image Box - 10 Dec 2013 03:14
Toggle Tag - 19 Jul 2013 11:13
Hide Tags - 14 Feb 2013 21:35
Mini Chat Area - 15 May 2012 12:04
Table Alterations - 16 Feb 2012 01:45

Rate this solution

If you think this solution is useful — rate it up!

rating: +6+x
Add a New Comment
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License