Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2007-12-16 11:30:13

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Change the page template if within category

I have a page template assigned to a section, let’s say News. On the News landing page (section page) I have one design, but I would like to a different layout on the category pages.

For example, user goes to News and sees one layout, then clicks on World News (an article or a category within the News section), and a different layout is used.

I could use if_section or if_category conditionals for the style layout elements, but wondering if someone has come across a better/cleaner way.

Offline

#2 2007-12-16 14:19:01

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,538
Website GitHub Twitter

Re: Change the page template if within category

Hi

Have you try to make link to a category by specifying a section (look at txp:category_list), you can make your link like this : yoursite.com/thesection/?c=category, then the category is viewed using template of thesection

Offline

#3 2007-12-16 14:32:35

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Change the page template if within category

Thanks Dragondz. I have what you describe in the current template, but wanted to change the design, hence the question. I solved it by using if_individual_article conditionals…..

Offline

#4 2007-12-16 15:07:33

Pat64
Plugin Author
From: France
Registered: 2005-12-12
Posts: 1,634
GitHub Twitter

Re: Change the page template if within category

Jonathan,
based on Dragondz reply, it seems you need to obtain the category with a get method. With some PHP lines into your <head> to call your css rules.

Last edited by Pat64 (2007-12-16 15:08:24)


Patrick.

Github | CodePen | Codier | Simplr theme | Wait Me: a maintenance theme | [\a mi.ni.ma]: a “Low Tech” simple Blog theme.

Offline

#5 2007-12-16 15:18:47

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Change the page template if within category

I use nested txp:output_form-tags and txp:if_category to do these shorts of things. Style changing could be done with <body id="<txp:category />" or <txp:if_category><link rel="stylesheet" type="text/css" media="screen" href="<txp:site_url />textpattern/css.php?n=<txp:category />" /></txp:if_category>

Cheers!

Offline

#6 2007-12-16 15:40:00

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Change the page template if within category

Well, this is how I did it, might bring in some comments…

<!-- content -->
<div id="content">

<txp:if_individual_article>
<div id="leftlarge">
<txp:article limit="1" />
</div>
<div id="rightsmall">
<txp:if_article_id id=157>
<txp:output_form form="some_form" />
</txp:if_article_id>
</div>

<txp:else />

<div id="maincontent">
<div id="left"><txp:article status="sticky" form="sticky" limit=1 />
</div>
<div id="right">
<p>This is paragraph text</p>
</div>
<!-- end right --></div>
<!-- end maincontent -->
</div>
<div id=subcontent>
<txp:if_article_list>
<txp:article form="some_other_form" />
</txp:if_article_list>
<!-- end subcontent -->
</div>

</txp:if_individual_article>

<!-- end content -->
</div>

Offline

Board footer

Powered by FluxBB