Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Automagically adding 's' to download count text
In the book ‘Textpattern Solutions’ the author has a nifty trick to add an ‘s’ on the end of comment count results unless the count is ‘1’ (because “1 Comments” is grammatically wrong). The code is as follows…
comment<txp:php>
if ($GLOBALS[‘thisarticle’][‘comments_count’] != 1)
{
echo ‘s’;
}
</txp:php>
I would also like to use this method for download counts too (in a file form), but as I’m hopeless at php I don’t know how to do it, I tried the following without success…
download<txp:php>
if ($GLOBALS[‘thisfile’][‘downloads’] != 1)
{
echo ‘s’;
}
</txp:php>
Any idea on what the correct method would be?
Thanks,
Phil
Offline
Re: Automagically adding 's' to download count text
Here’s an untested idea using tags rather than raw PHP:
<txp:variable name="download_count" value='<txp:file_download_downloads />' />
download<txp:if_variable name="download_count" value="1"><txp:else />s</txp:if_variable>
Last edited by jsoo (2009-09-17 11:55:33)
Code is topiary
Offline
Re: Automagically adding 's' to download count text
Thanks a lot, works great.
<txp:if_variable> was not available when the book was written (in 1997), so this is a much cleaner method. I’ll use <txp:if_variable> to replace the php in the first example too.
Cheers.
Offline
Offline
Re: Automagically adding 's' to download count text
Oops, yes, 2007!!!
Offline