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

4 views
Skip to first unread message

Hans

unread,
Feb 28, 2008, 4:40:34 PM2/28/08
to christian....@gmail.com, pmwiki...@pmichaud.com
Thursday, February 28, 2008, 4:33:10 PM, christian....@gmail.com wrote:

> Is there a way to get a list of which categories a partuclar page belongs to?

you can try markup erxpression {(catlist)}
http://www.pmwiki.org/wiki/Cookbook/MarkupExpressionSamples

Note that the page will be opened, as the expression has to look
through the page to find category links.
The default output is a csv list.

Another way for showinfg actual cat links may be to put your cat
links always into an anchored section, and then include that page
section in your pagelist listing (change the fmt for that).


~Hans


_______________________________________________
pmwiki-users mailing list
pmwiki...@pmichaud.com
http://www.pmichaud.com/mailman/listinfo/pmwiki-users

christian....@gmail.com

unread,
Feb 28, 2008, 4:33:10 PM2/28/08
to Pmwiki...@pmichaud.com
Hi,

I'ld like to modify how category pages are shown. Today I'm using the following
as Category.GroupHeader

(:pagelist link=Cateogory.{$Name} fmt=simple list=normal:)

The result is a list of pages that belong to the current category. I'll give an
example, let's say the current category is 'Movies', and the list of pages is
as follows:

* Gone with the wind
* Blues Brothers
* Red planet

What I would like is to also be able to see what (other) categories these pages
belong to, e.g. like this:

* 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?

/Christian

--
Christian Ridderström, +46-8-768 39 44 http://www.md.kth.se/~chr

Patrick R. Michaud

unread,
Feb 28, 2008, 8:30:31 PM2/28/08
to christian....@gmail.com, Pmwiki...@pmichaud.com
On Thu, Feb 28, 2008 at 05:33:10PM +0100, christian....@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.

Pm

Peter & Melodye Bowers

unread,
Feb 28, 2008, 8:09:49 PM2/28/08
to christian....@gmail.com, Pmwiki...@pmichaud.com, Peter Gmail Bowers, SentN
I believe that Hans has put together a form of pagelist which works from
within an MX instead of a standard MX. Using that format and combining it
with some of the tools in WikiSh will result in something pretty close to
what you're looking for. It will look something like this:

{(sed 's/^[^\[]*(\[\[![^\]]*\]\]).*$/\\1/' - (grep --line_prefix:'*
PAGETITLE: ' '\[\[!.*\]\]' (pagelist link=Category.{$Name}
fmt=simpletext)))}

That solution assumes that you will only ever have a single category on a
single line in the source. The regex would have to get a little more
complicated to allow more than one category on a line. Given that
assumption, this brings us to this point:

* Gone with the wind: [[!Movies]]
* Gone with the wind: [[!Drama]]
* Blues Brothers: [[!Movies]]
* Blues Brothers: [[!Musical]]
* Red planet: [[!Movies]]
* Red planet: [[!Science Fiction]

I don't know if that is close enough for you or not.

The {(catlist)} that Hans pointed out has potential to do exactly what you
want with a little modification. Basically you just need to get it to read
the {(pagelist ...)} output to get the list of pages and then prefix the
list of categories with the title and format everything nicely...

-Peter

PS The code above is untested. If you're actually going to use it I can
copy it onto a page and get it a little more exact for you...

Randy

unread,
Feb 28, 2008, 10:19:25 PM2/28/08
to Patrick R. Michaud, christian....@gmail.com, Pmwiki...@pmichaud.com
Pm's CategoryList page variable seems very handy. Unfortunately it didn't display anything for me.

My page simply contains:

Category: [[!Tag1]], [[!Tag2]] (:markup:) Categories found on this page: {$CategoryList} (:markupend:)

and in config.php I have:
$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; }

Has it worked for anyone else?

Randy

Randy

unread,
Feb 28, 2008, 10:33:06 PM2/28/08
to Patrick R. Michaud, christian....@gmail.com, Pmwiki...@pmichaud.com
I get no results when I save the page. I'm using beta65.

Randy

On Feb 28, 2008, at 4:23 PM, Patrick R. Michaud wrote:
>
> If it's still not working for you... what version of PmWiki
> are you using?

Patrick R. Michaud

unread,
Feb 28, 2008, 10:23:19 PM2/28/08
to Randy, christian....@gmail.com, Pmwiki...@pmichaud.com
On Thu, Feb 28, 2008 at 04:19:25PM -0600, Randy wrote:
> Pm's CategoryList page variable seems very handy. Unfortunately it didn't
> display anything for me.
> My page simply contains:
> Category: [[!Tag1]], [[!Tag2]] (:markup:) Categories found on this page:
> {$CategoryList} (:markupend:)

Just to verify: $CategoryList will only work for the last _saved_
version of a page -- i.e., using "preview" from an edit page
won't use the categories in the current edit window.

If it's still not working for you... what version of PmWiki
are you using?

Pm

Reply all
Reply to author
Forward
0 new messages