Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-05-04 16:33:59

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

If 2+ articles

Hey
I have a list of future articles
and I want that in case I got only 1 future article it will show noting
and in case there are 2+ articles it will show some code

example:

<txp:if_2+_articles section=“blabla” time=“future”>
select: <txp:article_custom form=“blabla” pgonly=“0” section=“blabla” time=“future” />
<txp:else />
<!— nothing —>
</txp:if_2+_articles>

Is it possible please?

Offline

#2 2009-05-04 17:17:00

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

Re: If 2+ articles

This TXP Tip shows how to achieve what you want, in a slightly different context, using the variable and if_variable tags. You can adapt it to your needs.

Offline

#3 2009-05-04 17:23:49

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: If 2+ articles

Although the offset trick used on the tip Els suggested is very clever, I think it’s overkilling.
Well… maybe the solution I propose also seems a bit overkilling (needs one plugin, at least, or two plugins, at most)

You can try the modified version of rvm_counter or adi_calc to count thinks in tandem with smd_if (a swiss knife you gotta have in your TXP installations). Just iterate over TXP articles somewhere (probably, at the top of your page), count things, and then test them using smd_if.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#4 2009-05-04 17:30:47

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

Re: If 2+ articles

maniqui wrote:

Although the offset trick used on the tip Els suggested is very clever, I think it’s overkilling.

Yeah, I have this strange inclination to try and do as much as possible without plugins… ;)

Offline

#5 2009-05-04 18:02:12

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: If 2+ articles

Thanks Els & maniqui for the reply
but what variable do I need to use and how to use it please?
sorry I only know html&css =(

Offline

#6 2009-05-04 19:18:49

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

Re: If 2+ articles

<txp:variable /> and <txp:if_variable>. Use them like in the example on TXP Tips. Something like this:

<!-- check if there are any future articles in this section -->
<txp:variable name="hasarticle" value='<txp:article_custom section="blabla" time="future" limit="1" />' />
<txp:if_variable name="hasarticle" value="">
	<!-- no future articles, display nothing -->
<txp:else />
	<!-- check if there is more than one article in this section -->
	<txp:variable name="morethanone" value='<txp:article_custom section="blabla" time="future" offset="1" limit="1" />' />
	<txp:if_variable name="morethanone" value="">
		<!-- only one future article, display nothing -->
	<txp:else />
		<!-- more than one future article, display the articles -->
		<txp:article_custom section="blabla" time="future" form="blabla" />
	</txp:if_variable>
</txp:if_variable>

Offline

#7 2009-05-04 19:38:12

THE BLUE DRAGON
Member
From: Israel
Registered: 2007-11-16
Posts: 637
Website

Re: If 2+ articles

works great!
thanks =)

Offline

Board footer

Powered by FluxBB