Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2023-12-15 12:48:59

Gallex
Member
Registered: 2006-10-08
Posts: 1,289

category1 and category2 together

i have news frontpage. if i post news into ‘boys’ and ‘girls’ categories, output should look:

…| Kat: Boys, Girls

my code:

<span class=“posted”><txp:posted format=”%d.%m.%Y” /> | Kat: <txp:category1 section=’<txp:section />’ title=“1” link=“1” /></span>

Offline

#2 2023-12-15 14:35:03

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,596
Website

Re: category1 and category2 together

You need to also use txp:category2 and with the help of txp:evaluate or the wraptag=", <+>" attribute (this may be txp4.9 only, I can’t remember), you can show it conditionally with a comma:

<span class="posted">
    <txp:posted format="%d.%m.%Y" /> | 
    Kat: <txp:category1 section='<txp:section />' title="1" link="1" /><txp:evaluate test="category2">, <txp:category2 section='<txp:section />' title="1" link="1" /></txp:evaluate>
</span>

or

<span class="posted">
    <txp:posted format="%d.%m.%Y" /> | 
    Kat: <txp:category1 section='<txp:section />' title="1" link="1" /><txp:category2 section='<txp:section />' title="1" link="1" wraptag=", <+>" />
</span>

TXP Builders – finely-crafted code, design and txp

Offline

#3 2023-12-15 21:30:50

etc
Developer
Registered: 2010-11-11
Posts: 5,054
Website GitHub

Re: category1 and category2 together

There is yet another way:

<txp:category_list categories='<txp:category1 />, <txp:category2 />' break=", " trim>
     <txp:category title link />
</txp:category_list>

Offline

#4 2023-12-15 22:11:45

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 11,271
Website GitHub

Re: category1 and category2 together

etc wrote #336162:

There is yet another way

All excellent suggestions. That <+> is so handy sometimes.

Oleg’s is what I’d use for simplicty because it also allows you to add label=" | Kat: " labeltag="span" (or whatever), so the label only shows up if there’s at least one category set.

I love these global attributes.

Last edited by Bloke (2023-12-15 22:13:38)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Txp Builders – finely-crafted code, design and Txp

Offline

#5 2023-12-19 10:34:34

Gallex
Member
Registered: 2006-10-08
Posts: 1,289

Re: category1 and category2 together

etc wrote #336162:

There is yet another way:

<txp:category_list categories='<txp:category1 />, <txp:category2 />' break=", " trim>...

brilliant!

Offline

Board footer

Powered by FluxBB