Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2011-03-06 10:47:47

gomedia
Plugin Author
Registered: 2008-06-01
Posts: 1,373

Re: Zebra stripes every two articles

caruso_g wrote:

Wonderful solution (and now reference…!) but unluckily (apart that it seems printing first div class="odd") it doesn’t print on last div in case of odd number of features.

Oops, but easily fixed though, just add this after the <txp:article> tag :

<txp:if_variable name="article_count" value="1">
	</div>
</txp:if_variable>

And just for good measure – to further demonstrate the power of variables, counters & conditions – here’s a general purpose solution, where you can change the number of articles per <div> easily, just by changing the value of a TXP variable “group_size”. It dispenses with smd_if but uses the reset facility in adi_calc (which I’d forgotten about).

<txp:variable name="group_size" value="3" />
<txp:variable name="article_count" value="0" />
<txp:variable name="group_count" value="0" />

<txp:article>
	<txp:if_variable name="article_count" value="0">
		<txp:adi_calc name="group_count" add="1" reset="2" />
		<txp:if_variable name="group_count" value="0">
			<div class="even">
		<txp:else />
			<div class="odd">
		</txp:if_variable>
	</txp:if_variable>
	<p><txp:title /></p>
	<txp:adi_calc name="article_count" add="1" reset='<txp:variable name="group_size"/>' />
	<txp:if_variable name="article_count" value="0">
		</div>
	</txp:if_variable>
</txp:article>

<txp:if_variable name="article_count" value="0">
<txp:else />
	</div>
</txp:if_variable>

o.t. Adi, what about your great adi_menu next big release? It is working like a charm here! ;)

Funny you should ask – there’s a new release imminent!

Offline

#14 2011-03-06 12:19:00

maniar
Member
From: Hamilton, Ontario
Registered: 2010-01-04
Posts: 66
Website

Re: Zebra stripes every two articles

@caruso_g – I admit I like your idea of zebra striping article lists. I had only done that for comments in the past. Don’t mind my stealing your idea ;-)

If you opt for the Jquery solution combined with css, you’d only need to put the following line in your header:

<script type="text/javascript" >
	$(document).ready(function() {
		$('.article li:even').addClass('even');
	});
</script>

Every even ‘li’ that inside ‘article’ class will be given the ‘even’ class .

Edit: Check out this documentation: jQuery – Zebra striping made easy

Last edited by maniar (2011-03-06 12:28:48)


اردو میں بھی دستیاب Textpattern آپ کے لیے اب

Offline

Board footer

Powered by FluxBB