Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-10-29 19:26:03

zeeforel
Member
From: Nieuwerkerk a/d IJssel, NL
Registered: 2004-10-16
Posts: 92
Website

Small change in template based on category of articles displayed

Hi to you all,

On my blog I want to prepare for some variation in the page template based on the category of the articles displayed. So:
+ for www.shapingthoughts.com/category1/ I want a slightly different template then for
+ for www.shapingthoughts.com/other categories/

The variation relates to some changes in the left bar (so to static elements), where I want to use a bit of Adsense for a specific category only.

Can this be done?

Not wanting to complicate things further, but the condition for changing the template could also relate to a specific article being displayed (in stead of all articles under a category), having a particular category (category1 in the example).

Btw, I found this, but I am not sure it is the solution to my problem. Maybe I should use some PHP in my template?

Many thanks in advance!

Best regards,
Marcel

Offline

#2 2006-10-29 20:22:57

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

Re: Small change in template based on category of articles displayed

Hi Marcel,

Sure you can do that with a conditional tag. In the left bar:

<txp:if_category name="category1">
content/code for category1 page here
<txp:else />
content/code for other categories here
</txp:if_category>

And you can use it again where you want to display the specific article:

<txp:if_category name="category1">
<txp:article_custom id="x" />
<txp:else />
here the regular article tag
</txp:if_category>

Offline

#3 2006-10-29 20:51:42

zeeforel
Member
From: Nieuwerkerk a/d IJssel, NL
Registered: 2004-10-16
Posts: 92
Website

Re: Small change in template based on category of articles displayed

Hi Els,

Thanks for the reaction. However, I tried to put the first piece of code in the left bar and it did not work!

The code itself works but is only shows the results after <txp:else /> so the specific code based on a category in the articles being displayed is not published.

Any idea?

By the way: I do not put article tags in the <txp:if_category> tag, only static code! Maybe that is the issue here?

Finally: what do you mean with the second example?

Best regards,
Marcel

Last edited by zeeforel (2006-10-29 20:52:07)

Offline

#4 2006-10-29 21:01:21

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

Re: Small change in template based on category of articles displayed

zeeforel wrote:

The code itself works but is only shows the results after <txp:else /> so the specific code based on a category in the articles being displayed is not published.

Did you mean it should also work on an individual article page? Because my example is for article lists (category pages). For an individual article page you should use <txp:if_article_category> (you can use this tag on a page from 4.0.4, not before).

By the way: I do not put article tags in the <txp:if_category> tag, only static code! Maybe that is the issue here?

No, that doesn’t matter.

Finally: what do you mean with the second example?

I understood you also wanted conditional content in another spot than the left bar, because you said “a specific article being displayed (in stead of all articles under a category)”. This example was meant to use instead of your article tag with wich you display the article lists.

Offline

#5 2006-10-29 21:31:02

zeeforel
Member
From: Nieuwerkerk a/d IJssel, NL
Registered: 2004-10-16
Posts: 92
Website

Re: Small change in template based on category of articles displayed

Hi Els,

My original intend was to get it working on the category page, just like you pointed out. I tested that case with yoyr code, but it did not work (I am on 4.0.2 by the way; should upgrade I know!).

This is what I put in the page template:

<txp:if_category name="Adsense">
<p>test1</p>
<txp:else />
<p>test2</p>
</txp:if_category>

but “test2” keeps appearing!

I tried with other categories also… Any tips?

So, on an individual article page, I need to upgrade to 4.0.4 to get it working? However that’s phase 2 here.

Thanks in advance.

Best regards,
Marcel

Last edited by zeeforel (2006-10-29 22:14:49)

Offline

#6 2006-10-29 22:16:04

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

Re: Small change in template based on category of articles displayed

This code should work. Is your category name correct? Shouldn’t it be ‘adsense’ (all lower case)? You should use the name, not the title.

<txp:if_article_category> until now could only be used in an article form. In 4.0.4 you can also use it on the page, but I think you’ll have to wrap it in <txp:if_individual_article> tags.

Offline

#7 2006-10-29 22:21:48

zeeforel
Member
From: Nieuwerkerk a/d IJssel, NL
Registered: 2004-10-16
Posts: 92
Website

Re: Small change in template based on category of articles displayed

Hi Els,

You were absolutely correct about the lowercase! It solved the issue and now it works for the category page.

For the article page I need to upgrade first…tomorrow.

Many thanks for your assistance!!!

Best regards,
Marcel

Last edited by zeeforel (2006-10-30 06:34:32)

Offline

Board footer

Powered by FluxBB