Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-02-06 23:45:37

darock
Member
Registered: 2007-11-23
Posts: 54

If/else statement for creating a different background in the sidebar

I want the a new list of articles to appear in the sidebar depending on the section that we land on. So I know I can create this code here;

<txp:if_section name="children">
<txp:recent_articles section="children" label="" />
</txp:if_section>
<txp:if_section name="corporate">
<txp:recent_articles section="corporate" label="" />
</txp:if_section>

But how would I do it if I wanted a different background image to appear each and everytime depending on the section that appears for that sidebar?

Offline

#2 2008-02-06 23:52:38

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: If/else statement for creating a different background in the sidebar

Just apply a class or ID:

<txp:if_section name="children">
	<txp:recent_articles section="children" label="" class="different" />
</txp:if_section>
<txp:if_section name="corporate">
	<txp:recent_articles section="corporate" label="" />
</txp:if_section>

Then do .different { background: url(/images/something.png) } in your CSS.

Last edited by jm (2008-02-06 23:53:30)

Offline

#3 2008-02-07 00:08:45

darock
Member
Registered: 2007-11-23
Posts: 54

Re: If/else statement for creating a different background in the sidebar

Thanks so much. I take it that this can’t accept an id instead of a class?

Actually, I just tried an ID and I got an error, so IDs don’t work.

Last edited by darock (2008-02-07 00:16:55)

Offline

#4 2008-02-07 00:57:06

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: If/else statement for creating a different background in the sidebar

That is correct, though it probably should like the other TXP tags. You’ll get more control using article_custom though:

<ul id="recent_<txp:section">
	<txp:if_section name="children">
		<txp:article_custom form="recent_article" section="children" />
	</txp:if_section>
	<txp:if_section name="corporate">
		<txp:article_custom form="recent_article" section="corporate" />
	</txp:if_section>
</ul>

form: recent_article

<li>
	<txp:permlink>
		<txp:title />
	</txp:permlink>
</li>

Last edited by jm (2008-02-07 00:58:56)

Offline

Board footer

Powered by FluxBB