[pmwiki-users] Re: Getting a list of the cateogories that the current page belongs to?
chr at home.se
chr at home.se
Wed Oct 5 03:11:12 CDT 2005
Here's a new version of the code that manages a partial test to see if the
current page contains categories. Please note that it's only partial,
because it only checks the page by using ReadPage(), so any included pages
aren't checked. This latter part is rather big drawback, since I can
imagine putting [[!category]] in pages that are included.
/Christian
if(true) {
$Conditions['iscategorised'] = "TestForCategories(\$pagename, \$condparm)";
function TestForCategories($pagename, $altPagename) {
$p = ReadPage($altPagename == "" ? $pagename : $altPagename);
$a = CategoryArray($pagename, $p['text']);
return count($a) > 0;
}
Markup('iscategorised','>nl1','/\(:iscategorised:\)(.*)/se',
"IsCategorised(\$pagename,PSS('$1')).PSS('$1')");
function IsCategorised($pagename,$text) {
preg_match_all('/(\\[\\[!.*?\\]\\])/',$text,$m);
if (count($m[0]) == 0) return 'Please categorise this page.';
return 'Categories: '.implode(', ',$m[1]);
}
Markup('{$categories}', '>nl1',
'/\\{\\$categories\\}(.*)/se',
"implode(', ', CategoryArray(\$pagename,PSS('$1'))).PSS('$1')");
function CategoryArray($pagename, $text) {
preg_match_all('/(\\[\\[!.*?\\]\\])/',$text,$m);
return $m[1];
}
Markup('{$categoryItems}', '>nl1',
'/\\{\\$categoryItems\\}(.*)/se',
"CategoryList(\$pagename,PSS('$1')).PSS('$1')");
function CategoryList($pagename, $text) {
$a = CategoryArray($pagename, $text);
if (count($a) == 0)
return "";
else
return "* ".implode("
* ", $a);
}
}
--
Christian Ridderström, +46-8-768 39 44 http://www.md.kth.se/~chr
More information about the pmwiki-users
mailing list