[pmwiki-users] How to list the categories a page belongs to? (fwd)

Patrick R. Michaud pmichaud at pobox.com
Thu Feb 28 14:30:31 CST 2008

On Thu, Feb 28, 2008 at 05:33:10PM +0100, christian.ridderstrom at gmail.com wrote:
> * Gone with the wind     ([[!Movies]], [[!Drama]])
> * Blues Brothers         ([[!Movies]], [[!Musical]])
> * Red planet             ([[!Movies]], [[!Science Fiction]]
> Any ideas on how to do this?
> Is there a way to get a list of which categories a partuclar page belongs 
> to?

I suggest making a page variable for this:

    $FmtPV['$CategoryList'] = 'CategoryList($pagename, $page)';

    function CategoryList($pagename, $page) {
      preg_match_all('/(?:^|,)Category\.([^,]+)/', $page['targets'], $x);
      $out = '';
      foreach ($x[1] as $n) {
        $out .= "[[!$n]] ";
      return $out;

See http://www.pmwiki.org/wiki/Test/CategoryPV for a demo.


More information about the pmwiki-users mailing list