[pmwiki-users] Getting a list of the cateogories that the current page belongs to?

John Rankin john.rankin at affinity.co.nz
Tue Oct 4 19:08:11 CDT 2005


On Tuesday, 4 October 2005 8:23 AM, chr at home.se wrote:
>Hi
>
>I'd like to be able to have the group header (or possibly the sidebar)  
>display a list of the categories that the current page belongs
>to.
>
>Has anyone tried doing anything like this? 
>Is there some secret (:pagelist:)-command I could use? (You could rephrase 
>this problem as asking which pages in the group Category/, does the 
>current page link to using the [[!...]]-directive.)
>
>In an ideal world, I could also use a conditional statement to control the
>output depending on if the current pages belongs to any category at all.
>The condiational code in the group-header/footer might look
>like this:
>
>	(:if is-categorized {$Name}:)
>	Categories: (:pagelist-voodo:)
>	(:if ! is-categoriez {$Name}:)
>	Please categorize this page!
>	(:ifend:)
>
>/Christian
>
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.

I have given this a quick test and it seems to work.


-- 
JR
--
John Rankin






More information about the pmwiki-users mailing list