Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-07-13 12:21:20

Ace of Dubs
Member
Registered: 2006-04-17
Posts: 446

Making txp:if_category actually work

So I am finally getting comfortable enough with these wonderful tags to have them doing most of the heavy lifting on my site.

However there are times when I dont get the desired result

For example:

I want some content to be displayed on the landing page of a section but to be invisible to all individual article pages, EXCEPT those whose category is “Reviews”.

I made an article form with this:

<code><txp:if_article_list>
<!—Display Content>
</txp:if_article_list>
<txp:if_individual_article>
<txp:if_article_category name=“Reviews” number=“1”>
<!—Display Content>
<txp:else />
</txp:if_article_category>
</code>

I get the content showing up on the landing page but not on my Reviews page. Any idea why this doesn’t work?

Last edited by Ace of Dubs (2006-07-13 18:26:47)

Offline

#2 2006-07-13 12:38:46

creativesplash
Member
From: Coimbatore, India
Registered: 2005-01-19
Posts: 283
Website

Re: Making txp:if_category actually work

looks like you havent closed the <code><txp:if_individual_article></code>

<code><txp:if_article_list>
<!—Display Content>
</txp:if_article_list>
<txp:if_individual_article>
<txp:if_article_category name=“Reviews” number=“1”>
<!—Display Content>
<txp:else />
</txp:if_article_category>
</txp:if_individual_article><!—looks like you havent closed this tag like this —></code>


“Take a point, stretch it into a line, curl it into a circle, twist it into a sphere, and punch through the sphere.”

— Albert Einstein

Offline

#3 2006-07-13 12:55:25

Ace of Dubs
Member
Registered: 2006-04-17
Posts: 446

Re: Making txp:if_category actually work

nope…that was actually just a bad copy and paste job. My code reads identical to what you have but it doesnt work.

I even tried spicing things up with an else tag:

<code><txp:if_article_list>
<!—Display Content>
</txp:if_article_list>
<txp:if_individual_article>
<txp:if_article_category name=“Reviews” number=“1”>
<!—Display Content>
<txp:else /></txp:if_article_category>
</txp:if_individual_article></code>


It seems like if_article_category is not working for me at all, even though I have clearly set the category in my articles.

Edit: I just ran a test and this conditional, on it’s own, does nothing. It is simply getting ignored. I even tried inserting it into the article form itself (instead of the page template) but that dont work either.

Last edited by Ace of Dubs (2006-07-13 13:09:26)

Offline

#4 2006-07-13 13:50:05

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

Re: Making txp:if_category actually work

As far as I know <txp:if_article_category> can only be used in an article form.

Offline

#5 2006-07-13 14:49:29

Ace of Dubs
Member
Registered: 2006-04-17
Posts: 446

Re: Making txp:if_category actually work

Thats what I was thinking, but so far no luck. Been having recent problems with my database, so that could be the issue. Gonna test this on a fresh install..

Offline

#6 2006-07-13 17:49:08

Ace of Dubs
Member
Registered: 2006-04-17
Posts: 446

Re: Making txp:if_category actually work

Okay, installed from scratch and still having the same problems.

Due to the context of the situation, I have to keep these conditionals on my page template, so the new tags are like so:

<code><txp:if_individual_article>
<txp:if_category name=“Reviews”><!—CONTENT></txp:if_category>
</txp:if_individual_article></code>

This code shows nothing at all. I take out the category conditionals and it works. I even tried using JUST category to filter out results, but nothing shows up. Definitely a problem with the if_category tag… I wonder if it is because I am using clean URLs. I tried switching to messy mode, but my entire site goes 404 on me. This is really driving me crazy

Offline

#7 2006-07-13 22:10:56

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

Re: Making txp:if_category actually work

It doesn’t work because <txp:if_category> looks for a category list. You need <txp:if_article_category> because that tag looks for the category a specific article is in. And you can only use that in an article form because the tag otherwise wouldn’t ‘know’ which article’s category to look for.
I think you can do it this way:

On the page:
<code>
<txp:if_article_list>
<!—Display Content>
</txp:if_article_list>
<txp:if_individual_article>
<txp:article form=“specialform” />
</txp:if_individual_article>
</code>
Your form ‘specialform’:
<code>
<txp:if_article_category name=“Reviews”>
the content or tags you want for this specific category
<txp:else />
the tags you have in your normal article form
</txp:if_article_category>
</code>

Last edited by els (2006-07-13 22:12:57)

Offline

#8 2006-07-14 00:28:04

Ace of Dubs
Member
Registered: 2006-04-17
Posts: 446

Re: Making txp:if_category actually work

Thanks for the code.

I actually ended up solving the problem by making another section, but it’s good to have a better understanding of how these tags operate in different situations.

cheers

Offline

Board footer

Powered by FluxBB