Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-07-27 21:20:29

Plaz
Member
From: Minnesota
Registered: 2004-06-02
Posts: 33

Display conditional text based on the articles category?

Hello,

I am trying to have a page display a block of text and some minor graphics based on what category an article is in.

In one column on the page, I have a space reserved for contact information. In another column, articles will display.

In the first column, I want the contact info to change based on the category that the article in the right hand column is in…

I was hoping that if_category would work… but I cannot get it to.

I want it do do something like this in the first column:

If category=“apples”
display“Bob Jones, 555-555-1212”

If category=“oranges”
display“kathy Hart, 555-555-1214”

If category=“kiwi”
display“Jean Hackman, 555-555-1216”

else
show the default image

Is there a simple way to do this?

I’ve been working on this for hours and going nutso in the process… thanks…


If you want something you have never had, then you must be willing to do something you have never done.

Offline

#2 2006-07-27 21:46:41

ricetxp
Member
From: London, UK
Registered: 2005-05-24
Posts: 89
Website

Re: Display conditional text based on the articles category?

<code>
<txp:if_category>
<txp:output_form form=“addresses” />
<txp:else />
default content goes here
</txp:if_category>
</code>

Then create a form called addresses and put in the following:
<code>
<txp:if_category name=“apples”>
content goes here
</txp:if_category>
<txp:if_category name=“oranges”>
content goes here
</txp:if_category>
and so on…
</code>

Offline

#3 2006-07-27 23:32:05

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Display conditional text based on the articles category?

<txp:if_category> looks at the category of an article list (so the category that is in the url). For an article category you need txp:if_article_category in the article form. To use it the way you want to, you’d need two article tags on the page.

In the column:
<code>
<txp:if_individual_article>
<txp:article form=“blah” />
</txp:if_individual_article>
</code>
Form ‘blah’:
<code>
<txp:if_article_category name=“apples”>
Bob Jones, 555-555-1212
</txp:if_article_category>
…and so on for the other categories
</code>
Remember to set ‘automatically append comments to articles’ to ‘no’, otherwise you’ll get into trouble with comments.

Offline

#4 2006-07-28 08:43:20

ricetxp
Member
From: London, UK
Registered: 2005-05-24
Posts: 89
Website

Re: Display conditional text based on the articles category?

DOH! Els is right. Forget my gibberish.

Offline

#5 2006-07-28 17:23:10

Plaz
Member
From: Minnesota
Registered: 2004-06-02
Posts: 33

Re: Display conditional text based on the articles category?

Excellent. This works perfectly. I appreciate your help on this.

In the column:

<code>
<txp:if_individual_article>
<txp:article form=“blah” />
</txp:if_individual_article>
</code>
<BR>
Form ‘blah’:
<BR>
<code>
<txp:if_article_category name=“apples”>
Bob Jones, 555-555-1212
</txp:if_article_category>
</code>
<BR>
…and so on for the other categories


If you want something you have never had, then you must be willing to do something you have never done.

Offline

Board footer

Powered by FluxBB