Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-02-28 00:06:57

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

[Solved] <txp:if_category number="2">

I know that attribute doesn’t exist, but I sure wish it did. I want to setup conditional output so that if two categories are used, both are output to show what the two categories are for a given article. If not, then only the first one.

For example, let’s say category1 = twigs and category2 = berries.
Then we’d get one category if only cat 1 and both categories if cat 2 also existed:

  1. Added to Twigs.
  2. Added to Twigs & Berries.

Using the imaginary attribute, number="2", a conditional cluster like this could make it work…

Put in <a class="capitalize" href="/topics/<txp:category1 />"><txp:category1 title="1" /></a><txp:if_category number="2">&amp; <a class="capitalize" href="/topics/<txp:category2 title="1" />"></txp:if_category>.

Is there any other way to do this? Can this attribute be a feature request if not?

Offline

#2 2014-02-28 00:42:22

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

Re: [Solved] <txp:if_category number="2">

Destry wrote #279314:

I want to setup conditional output so that if two categories are used [snip]

So you probably want to look at <txp:if_article_category> then, which does have the number attribute :-) Through judicial use of some txp:variable / txp:if_variable you could even make your own tag for it if you like, but there’s probably not much need unless you want to do some super-crunjo extra processing or clever output.

Does that help at all?


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

#3 2014-02-28 01:12:18

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: [Solved] <txp:if_category number="2">

Heh… I believe that does help. Thanks, sire.

Offline

#4 2014-02-28 06:55:03

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,171
Website GitHub Mastodon Twitter

Re: [Solved] <txp:if_category number="2">

Destry wrote #279314:

Put in <a class="capitalize" href="/topics/<txp:category1 />"><txp:category1 title="1" /></a><txp:if_category number="2">&amp; <a class="capitalize" href="/topics/<txp:category2 title="1" />"></txp:if_category>.

Is there any other way to do this? Can this attribute be a feature request if not?

<txp:variable name="cat2" value='<txp:category2 title="1" />' />
<txp:if_variable name="cat2" value="">
<txp:else />
&amp;<a class="capitalize" href="/topics/<txp:category2 title="1" />">...

But Stef’s method is more efficient I believe:)


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#5 2014-02-28 09:36:42

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: [Solved] <txp:if_category number="2">

Yes, it’s effectively squared away using <txp:if_article_category>. Thanks.

Offline

Board footer

Powered by FluxBB