[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 02:52:40 CDT 2005
On 5 Oct 2005, John Rankin wrote:
> You might try something like this in a GroupHeader page:
>
> (:iscategorised:)
>
> With the following rule:
>
> 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]);
> }
>
> This scans the contents of the page for category markup
> and emits a list of matches.
Very neat. The markup works in normal pages and the group header.
When I tried it in the sidebar, it didn't work however. Do you have any
idea why?
I discovered the problem with the sidebar when I added a new function to
generate an itemized list (which I wanted to place in the sidebar). The
whole thing looks like this now:
if(true) {
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
--
Christian Ridderström, +46-8-768 39 44 http://www.md.kth.se/~chr
More information about the pmwiki-users
mailing list