Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2014-11-17 09:26:07

MrViSiOn
Member
Registered: 2014-11-17
Posts: 26

txp:article_custom odd and even

Hi:

I’m new in textpattern, and I have an issue that I can not be able to fix… It just about detect odd and even txp:article_custom section=“onesection, othersection”, for adding thumbnails image only to odd

Is there any way to do this?

Thank you!

EDIT: If you need some details, just tell me, and I’ll describe this better

Last edited by MrViSiOn (2014-11-17 09:29:53)

Offline

#2 2014-11-17 10:10:42

etc
Developer
Registered: 2010-11-11
Posts: 3,273
Website

Re: txp:article_custom odd and even

Hello, welcome to txp!

Try this article form:

<txp:if_variable name="even" value="1">
	no thumbnail
	<txp:variable name="even" value="0" />
<txp:else />
	<txp:thumbnail />
	<txp:variable name="even" value="1" />
</txp:if_variable>

Edit: removed the erroneous closing / from if_variable.

Last edited by etc (2014-11-17 10:19:51)


etc_[ query | search | pagination | date | tree | cache ]

Offline

#3 2014-11-17 10:12:12

MrViSiOn
Member
Registered: 2014-11-17
Posts: 26

Re: txp:article_custom odd and even

mmm… Easy and good solution!

Thank You, It works!

Offline

#4 2014-11-18 16:21:00

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,400

Re: txp:article_custom odd and even

etc

Clever, it works. But, I’m confused, how or why it works? Can you explain it?

Offline

#5 2014-11-18 17:22:39

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,194
Website

Re: txp:article_custom odd and even

GugUser wrote #285899:

etc

Clever, it works. But, I’m confused, how or why it works? Can you explain it?

It is a classic example of Boolean Logic.

The first time through the loop even hasn’t been set to a value so it will be false – which will display a thumbnail and set even to true. The second even will be true so no thumbnail is displayed and even is set to false. And then the pattern will repeat.

In the wiki, there is an even more complex version with 3 columns (which not to brag but it was based on something I used in a template at one point).

Offline

#6 2014-11-18 20:54:38

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,400

Re: txp:article_custom odd and even

Thanks michaelkpate.

My confusion was because before the <txp:if_variable name="even" value="1"> is no variable definition. But as it seems, this is not necessary.

Offline

#7 2014-11-18 21:47:22

michaelkpate
Moderator
From: Avon Park, FL
Registered: 2004-02-24
Posts: 1,194
Website

Re: txp:article_custom odd and even

GugUser wrote #285902:

Thanks michaelkpate.

My confusion was because before the <txp:if_variable name="even" value="1"> is no variable definition. But as it seems, this is not necessary.

That is correct. If a variable hasn’t been defined, it can’t have been set to “1” so it will take the false branch in this case. There are languages that require variables to be initialized first but that doesn’t apply here.

Offline

Board footer

Powered by FluxBB