Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-09-17 11:24:34

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

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

#2 2009-09-17 11:54:05

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

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

#3 2009-09-17 12:23:12

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

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

#4 2009-09-17 15:45:30

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Automagically adding 's' to download count text

philwareham wrote:

when the book was written (in 1997)

Heh, TXP isn’t that old. Add 10 year to that (2007) ;)

Offline

#5 2009-09-17 15:57:11

philwareham
Core designer
From: Haslemere, Surrey, UK
Registered: 2009-06-11
Posts: 3,564
Website GitHub Mastodon

Re: Automagically adding 's' to download count text

Oops, yes, 2007!!!

Offline

Board footer

Powered by FluxBB