Here we want to produce a grid layout using the counting capabilities of adi_calc and with plenty of styling hooks. We’ll be using the reset
and reset_counter
attributes in version 1.1 of the plugin.
The Tools
- Textpattern 4.0.7+
- adi_calc version 1.1+
The Code
In the code below, we’re:
- Explicitly initialising the counters & in true programming tradition everything starts at zero
- Looping through a series of articles
- For each article, create some markup & display the counter values
Notes:
- the wrapping
<div>
is there to make life simple & obvious - the counter values are displayed in the output for demonstration purposes only
- the example articles don’t actually have any bodies to output!
- the number of columns can be adjusted very easily, simply by changing the reset value in the last call of adi_calc
- use
<txp:if_last_article>
if you want to do something special with the last article (#9 in the example)
The Styling
This will produce the example output.
The above example is simply a demonstration but the possibilities are endless. For example, in real life you might want to set the number of columns as a variable for use in the reset
and also to identify the last column (i.e. when column count = number of columns – 1). Or you could even implement alternating effects (zebra stripes?) using smd_if with it’s divisible
operator.