Textpattern CMS support forum
As of Txp 4.3.0RC1 Remillard’s original plugin no longer works.
It is now adopted and adapted by cain-mi, for the rewritten version and instructions see post #61.
Original posting by Remillard
This plugin is … well pretty basic. It will count the number of live articles in a section, or category.
<txp:mdn_count [section="sectionname"] [category="text"] />
NOTE: The items in square brackets are optional and the brackets should not be used in the construction of the tag.
- section – This item is OPTIONAL. The plugin will return the number of articles in the given section name.
- category – This item is OPTIONAL. The plugin will return the number of articles with the given category name, in either category1 OR category2.
- There is some basic checking. The two parameters are optional, but it doesn’t make sense if BOTH are gone. I think that’s the only one it catches.
- Section takes precedence over category if both are specified.
Download the plugin (Newer version available, see above.)
Changes since 1.3: There was a logic error that made it possible for the plugin to count the occasional draft copy if the category match was in category2.
Changes since 1.2: Added the ability to count the intersection of section and category, and removed the error message if there were no qualified count parameters specified.
Changes since 1.1: Fixed the ability mentioned below because I was stupid and did the change too fast. It ought to actually work now.
Changes since 1.0: Added the ability to take the section name or category name from the current section or category by calling out section=”#”, or category=”#”.
Last edited by uli (2012-11-30 15:15:40)
Er, no. Just articles in sections and categories. It’s very limited in that respect. I had an entire list of functional requirements for this one, and finally after much work I had to omit the “count the number of needles in Textpattern”.
Terribly sorry about that.
:-) Well actually the hard plugin was the mdn_if_custom one… getting the searches to work right was sort of tricky. <code>stripos()</code> is only in PHP 5, so I had to start working around case issues… and then getting the <code><else /></code> was interesting.
But it was still pretty much a day long PHP project… not a lengthy one.
Thank you for this plugin, I’ve been wanting this for a long time.
Is there also a way to make it count the articles in the current category? I tried something like <code>category=<txp:c /></code> but that doesn’t work.
Last edited by doggiez (2004-11-24 18:19:25)
Mmm… interesting idea to embed tags into parameters. Unfortunately no, it doesn’t do this, although it might not be too hard. If you wanted to try, go into the code on the plugin and put in something like this:
<code> $category = parse($category); </code>
Put it somewhere after the beginning and before it’s used and see what happens.
Whoops! Got it working! With hardly any php knowledge…
I changed the last part into:
$category = parse($GLOBALS[“c”]);
$q = “SELECT COUNT count FROM “.PFX.“textpattern WHERE
category1=’$category’ OR category2=’$category’ AND status=‘4’”;
$rs = getRows($q);
(parse($category) gave the the total amount of articles in all categories)
Haha, that was not that smart, because on another page I used the original plugin, which now won’t work anymore…
Is there a way to copy my modification and save it as another plugin?
Last edited by doggiez (2004-11-24 21:12:50)
Glad it worked. I think you could just put the parse category thing in there, and then use a tag in the parameter… er, well that might screw up the regular expression for the callback… this is maybe better.
As for a new version… unfortunately, not really. You’d have to put it into the plugin template, generate the md5 code and reupload it.