NumberOfArticles
Goal
Report the number of articles existing in the wiki.
Solution
1. Add the following lines to config.php:
## Add (:numberofarticles:) tag functionality $na = NumArticles(); Markup('(:numberofarticles:)', '_begin','/\\(\\:numberofarticles\\:\\)/', "$na"); function NumArticles() { if ($dir = opendir('wiki.d/')) { while (($file = readdir($dir)) !== false) { if (substr($file,0,1) != '.' && strpos($file, 'Site.') === false) { $list[] = $file; } } closedir($dir); } $NumArticles = count($list); return $NumArticles; }
2. Put (:numberofarticles:) in a page on your wiki.
You can change the tag if you wish. I initially used to correspond with the markup variables like {$Group} and {$Title}, but figured (:numberofarticles:) is more in harmony with the average user's expectation for this type of markup.
Notes
- When used Cookbook:Per Group SubDirectories , it can't work correctly.
~LiGuang
- Try CachedNumberOfArticles. -- Anomen April 13, 2007, at 01:16 PM
- Or try a PowerTools markup expression like
{(pagecount (plist group=*,-Site,-SiteAdmin))}
Request
Could this recipe be modified so that
- in counts the articles in a category
- the outcome can be included (via pagelist template)in a pagelist of categories?
So that (:pagelist #fmt=whatever link="Category.{$Name}" :)
gives as output:
Category1 (5 articles)
Category2 (9 articles)
18 feb 2006, Han
See also
- PowerTools -
{(pagecount (plist ...))}
expression
Comments
I've marked the recipe as obsolete, as its functionality can now be implemented using a pagelist, as follows. —Eemeli Aro July 29, 2009, at 01:04 PM
(:pagelist fmt=count:) |
10331 |
(:pagelist fmt=count group=Cookbook list=all:) |
2318 |
(:pagelist fmt=count link=Category.Obsolete:) |
71 |
THX for your comment. One additional hint from my side, all articles in Site.* are not counted because of
Any ideas to prevent this kind of behavior? Holger, July 21th, 2006
Articles in Site.* are not counted by design because why should already existing functionality count as content-style articles?
That's a good idea for the category counting. I'll look into it.
wanderful
I needed to count the Number of Articles only the group seen by the public, so I reversed the logic of the selection line so that it only included those pages within the desired group:
if (substr($file,0,1) != '.' && strpos($file, 'WantedGroup.') !== false){
so it only counts pages within the WantedGroup. Des July 23, 2007, at 09:05 AM
The original line that determines the article count includes all pages, unlike Search or PageList which can ignore core pages. By modifying the count to simply deduct the number of core pages, the count accuracy can be maintained. In my case the RecentPages and Sandbox pages increased the count by 2, so reducing final the count by 2:
$NumArticles = (count($list) - 2);
gave the correct Number of Articles. Des July 23, 2007, at 09:05 AM
Releases
0.3 - September 18th, 2006
0.2 - October 10th, 2005
0.1 - September 24th, 2005
Contributors
User notes? : If you use, used or reviewed this recipe, you can add your name. These statistics appear in the Cookbook listings and will help newcomers browsing through the wiki.