Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2004-08-25 23:02:12

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

[plugin] [ORPHAN] zem_nth

<txp:zem_nth> conditionally displays content every “n-th” step. Example uses:

  • Alternate or cycle colours and styles
  • Include a break only at specific positions in a list
  • Provide “glue” between articles in a list, without an extraneous element at the beginning or end

Download:

http://thresholdstate.com/download/zem_nth-0.1.txt

Docs and examples:

http://thresholdstate.com/software/3707/zemnth

Zem’s site is down. Here’s his latest plugin:

YToxMDp7czo0OiJuYW1lIjtzOjc6InplbV9udGgiO3M6NjoiYXV0aG9yIjtzOjM6InplbSI7czoxMDoiYXV0aG9yX3VyaSI7czoxOToiaHR0cDovL3ZpZ2lsYW50LnR2LyI7czo3OiJ2ZXJzaW9uIjtzOjM6IjAuMSI7czoxMToiZGVzY3JpcHRpb24iO3M6MzE6IkRpc3BsYXkgY29udGVudCBldmVyeSBuLXRoIHN0ZXAiO3M6NDoiaGVscCI7czoxNDE3OiI8cD4mbHQ7dHhwOnplbV9udGgmZ3Q7IGNvbmRpdGlvbmFsbHkgZGlzcGxheXMgY29udGVudCBldmVyeSAibi10aCIgc3RlcC4gIEV4YW1wbGUgdXNlczo8L3A+Cgo8dWw+CjxsaT5BbHRlcm5hdGUgb3IgY3ljbGUgY29sb3VycyBhbmQgc3R5bGVzPC9saT4KPGxpPkluY2x1ZGUgYSBicmVhayBvbmx5IGF0IHNwZWNpZmljIHBvc2l0aW9ucyBpbiBhIGxpc3Q8L2xpPgo8bGk+UHJvdmlkZSAiZ2x1ZSIgYmV0d2VlbiBhcnRpY2xlcyBpbiBhIGxpc3QsIHdpdGhvdXQgYW4gZXh0cmFuZW91cyBlbGVtZW50IGF0IHRoZSBiZWdpbm5pbmcgb3IgZW5kPC9saT4KPC91bD4KCkF0dHJpYnV0ZXM6Cgo8ZGw+CjxkdD5zdGVwPC9kdD48ZGQ+U3RlcChzKSBvbiB3aGljaCB0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ICRoaWdoKSk7DQoJCQl9DQoJCQllbHNlIHsNCgkJCQkkcmFuZ2VbXSA9IChpbnQpJGk7DQoJCQl9DQoJCX0NCg0KCQkjIEtlZXAgc2VwYXJhdGUgY291bnRlcnMgZm9yIGVhY2ggemVtX250aCB0YWcNCgkJJGlkID0gbWQ1KCRzdGVwLiAkdGhpbmcgLiAkb2YpOw0KDQoJCWlmICghaXNzZXQoJHplbV9udGhfY291bnRbJGlkXSkpDQoJCQkkemVtX250aF9jb3VudFskaWRdID0gMDsNCg0KCQkkcmVzdWx0ID0gTlVMTDsNCgkJaWYgKGluX2FycmF5KCR6ZW1fbnRoX2NvdW50WyRpZF0gKyAxLCAkcmFuZ2UpKQ0KCQkJJHJlc3VsdCA9IHBhcnNlKCR0aGluZyk7DQoNCgkJJHplbV9udGhfY291bnRbJGlkXSA9ICgkemVtX250aF9jb3VudFskaWRdICsxKSAlICRvZjsNCg0KCQlyZXR1cm4gJHJlc3VsdDsNCgl9DQoNCg0KIjtzOjQ6InR5cGUiO3M6MToiMCI7czo1OiJvcmRlciI7czoxOiI1IjtzOjM6Im1kNSI7czozMjoiNTVkZTc2MTk4MDZhOGE0MTFmNTMxNzQ3YmFiYTE1ZDIiO30=

Last edited by Mary (2008-02-09 03:20:28)


Alex

Offline

#2 2004-08-25 23:37:24

nednieuws
Member
From: The Home of Heineken
Registered: 2004-08-21
Posts: 14

Re: [plugin] [ORPHAN] zem_nth

Very nice, Zem.


Regards, Charles.

Offline

#3 2004-08-25 23:48:33

nednieuws
Member
From: The Home of Heineken
Registered: 2004-08-21
Posts: 14

Re: [plugin] [ORPHAN] zem_nth

<pre>
<!— range:Array
( [0] => 1
)
—>
<!— range:Array
( [0] => 2
)
—>
</pre>

Why is this prepended before the doctype?

Do you have any suggestions as to how to use this with comments? Comments are displayed as li’s, and how would I use this to alternate the class or background attribute of the li?


Regards, Charles.

Offline

#4 2004-08-26 00:41:50

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: [plugin] [ORPHAN] zem_nth

> Why is this prepended before the doctype?

My bad. Left some debugging info in there. Try downloading again.

> Do you have any suggestions as to how to use this with comments? Comments are displayed as li’s, and how would I use this to alternate the class or background attribute of the li?

Try something like this in your comment form:

<txp:zem_nth step=1 of=2><div class="red"></txp:zem_nth>
<txp:zem_nth step=2 of=2><div class="blue"></txp:zem_nth>
<txp:message /><br />
<small>— <txp:comment_name />    <txp:comment_time />
<txp:comment_permlink>#</txp:comment_permlink></small>
</div>

..with the appropriate classes in your CSS, of course.

Using a div isn’t the neatest solution, but I think the <li> markup is hard coded.

Last edited by zem (2004-08-26 00:49:35)


Alex

Offline

#5 2004-08-26 11:51:34

ChrisJ
Member
From: Vienna, Austria
Registered: 2004-03-30
Posts: 54
Website

Re: [plugin] [ORPHAN] zem_nth

how do I get the effect of <txp:zem_nth step=1 of=1><hr /></txp:zem_nth>, but without the <hr /> above the first item?

Offline

#6 2004-08-26 22:42:51

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: [plugin] [ORPHAN] zem_nth

step=1 of=1 will trigger on every step, no exceptions. of specifies the length of the cycle before it starts counting back at 1. “of=3” will count “1, 2, 3, 1, 2, 3, 1..”. “of=1” will count “1, 1, 1, 1, 1, 1..”

If you want a HR between every item (but not at the beginning or end), either use this at the beginning of your form:

<txp:zem_nth step="2-10"><hr /></txp:zem_nth>

OR use this at the end of your form:

<txp:zem_nth step="1-9"><hr /></txp:zem_nth>

That’s assuming there are 10 items in your list. If it’s a list where the length changes, use the first option with step="2-1000".

Last edited by zem (2004-08-26 22:43:22)


Alex

Offline

#7 2004-08-26 23:07:21

Andrew
Plugin Author
Registered: 2004-02-23
Posts: 730

Re: [plugin] [ORPHAN] zem_nth

Whoa this is a pretty cool idea. I’m not currently using it, but I’ve got to give you credit for creativity in development.

Offline

#8 2004-08-27 10:38:23

ChrisJ
Member
From: Vienna, Austria
Registered: 2004-03-30
Posts: 54
Website

Re: [plugin] [ORPHAN] zem_nth

Thanks, zem!

Offline

#9 2004-09-14 00:27:43

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: [plugin] [ORPHAN] zem_nth

Zem, I would like to output a list of articles (based on a category), and number them…

so the first article is headed ‘Day 1’, the second ‘Day 2’, etc

I can’t use an ordered list… and I don’t want to put ‘Day 1’ in the entry title… (depending on the category, Days could be 1 or 8 or 9 etc…)

I could do this in the article form:

<code>
<txp:zem_nth step=1 of=15>Day 1</txp:zem_nth>
<txp:zem_nth step=2 of=15>Day 2</txp:zem_nth>
<txp:title><txp:body>
</code>

whatcha reckon? is there a better way of doing it?

Offline

#10 2004-09-14 01:09:32

zem
Developer Emeritus
From: Melbourne, Australia
Registered: 2004-04-08
Posts: 2,579

Re: [plugin] [ORPHAN] zem_nth

Not with zem_nth. That would work, but get rather tedious as the length of the list increases.

Try something like this, in your article form:

<code>
<?php echo “Day “.@++$GLOBALS[‘mycounter’]; ?>
</code>


Alex

Offline

#11 2004-09-14 08:38:38

nardo
Member
From: tuvalahiti
Registered: 2004-04-22
Posts: 743

Re: [plugin] [ORPHAN] zem_nth

thanks zem, worked a treat

and I will endeavour to learn some php…

Offline

#12 2005-04-17 17:30:01

Maleika E.A.
Member
From: Hamburg, Germany
Registered: 2004-12-11
Posts: 39
Website

Re: [plugin] [ORPHAN] zem_nth

Hello zem,

this is a really great plugin. Thank you for this. :)

I do have a question.

Is it possible to use this plugin to do the following?

1 Article, different paragraph styles and divs.

Example:

<code>

<p class=“xy”>The first paragraph of the article uses the p class xy</p>
<p class=“xz”>The second paragraph in the same article uses the p class xz</p></code>

Or this option:
<code>
<div class=“style1”>This paragraph uses the style 1 division </div>

<div class=“style2”>This paragraph uses the style 2 division </div>
</code>

So basically, it would allow for a very detailed styling within a single article and – simultaneously – reduce the amount of style information stored within the article and just have the zem_nth function in the page that is assigned to the article …

Not sure whether I’ve explained this reasonably or whether it is possible to do such a thing. I thought of a way to – say – have some tag between each paragraph within the article itself.I have no clue about php, so I might be thinking in very unrealistic terms.

Thanks :)

Maleika

Last edited by Maleika E.A. (2005-04-17 17:46:50)

Offline

Board footer

Powered by FluxBB