Textpattern Forum

You are not logged in. Register | Login | Help

#1 2012-08-30 10:37:48

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 254
Website

Group article two by two

How can I group article by two like this?

<div class="group">
<article id="1" />
<article id="2" />
</div>
<div class="group">
<article id="3" />
<article id="4" />
</div>

Offline

#2 2012-08-30 10:52:00

Gocom
Developer
Registered: 2006-07-14
Posts: 4,476
Website

Re: Group article two by two

If those are set articles, you could use the article_custom and it’s id attribute, or any other selector. If it’s needs to be a context-sensitive or a consequent list split in half, you could use offset and limit. Works for both article and article_custom tags. When used with article tag, set the pageby attribute to the number of articles is displayed on a page. E.g.

<section>
	<txp:article limit="2" pageby="4" />
</section>
<section>
	<txp:article limit="2" offset="2" pageby="4" />
</section>

This all is mentioned clearly on the tag reference. For instance see the Example #4 on the article tag’s reference page.


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#3 2012-08-30 11:00:29

etc
Plugin Author
Registered: 2010-11-11
Posts: 1,268
Website

Re: Group article two by two

You can easily do it with etc_query. Suppose your articles are wrapped in article tag in your article form:

<article>
headers and other stuff
</article>

Then call something like this (not tested)

<txp:etc_query data='<txp:article />' query="//article[position() mod 2 = 1]">
<section>
  {.}
  {following-sibling::article[1]}
</section>
</txp:etc_query>

Last edited by etc (2012-08-30 11:09:52)


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

Offline

#4 2012-08-30 13:22:43

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 254
Website

Re: Group article two by two

Thanks!
I think I use Gocom method. I originally wanted to create list of article that dynamically splits every two articles, even if articles are more than 4.

Last edited by wornout (2012-08-30 13:49:45)

Offline

#5 2012-08-30 13:45:01

etc
Plugin Author
Registered: 2010-11-11
Posts: 1,268
Website

Re: Group article two by two

My solution is dynamic. :)


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

Offline

#6 2012-08-30 13:50:59

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 254
Website

Re: Group article two by two

etc wrote:

My solution is dynamic. :)

Yes, but I prefer to do that without any plug-in…

Offline

#7 2012-08-30 13:51:04

uli
Moderator
From: Cologne/Köln
Registered: 2006-08-15
Posts: 3,119

Re: Group article two by two

I still can’t read/interpret etc_query code, so I can’t tell whether olegs solution would work dynamically. But there’s still zem_nth, which was exactly developed for use cases like yours.

A pluginless solution can be built from wet’s zebra stripe tutorial.

Edit: A bit late, again :)

Last edited by uli (2012-08-30 13:51:45)


In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links

Offline

#8 2012-08-30 13:57:59

etc
Plugin Author
Registered: 2010-11-11
Posts: 1,268
Website

Re: Group article two by two

wornout wrote:

etc wrote:

My solution is dynamic. :)

Yes, but I prefer to do that without any plug-in…

I don’t blame you, that’s what I prefer too, but in the present case etc_query will work faster than multiple <txp:article /> calls. And probably, the most natural way is a mere CSS nth-of-type selector.


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

Offline

#9 2012-08-30 14:22:36

etc
Plugin Author
Registered: 2010-11-11
Posts: 1,268
Website

Re: Group article two by two

uli wrote:

I still can’t read/interpret etc_query code, so I can’t tell whether olegs solution would work dynamically.

You can see a quick demo here.


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

Offline

#10 2012-08-30 14:50:29

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 254
Website

Re: Group article two by two

etc wrote:

uli wrote:

I still can’t read/interpret etc_query code, so I can’t tell whether olegs solution would work dynamically.

You can see a quick demo here.

I’m trying to use your plug-in but something goes wrong and nothing appears in output:
This is my code:

<txp:etc_query data='<txp:article_custom section="prodotti" category="farine-alimentari" form="slide" />' query="//article[position() mod 2=1]">
<div class="slide">
{.}
following-sibling::article[1]}
</div><!-- slide -->
</txp:etc_query>

And slide form:

<div class="product-big">
<div class="left-box">
<a href="#"><img src="http://placehold.it/160x200" alt="" /></a>
</div><!-- left-box -->
<div class="right-box">
<div class="post">
<h3><txp:permlink><txp:title /></txp:permlink></h3>
<txp:excerpt />
<txp:permlink class="standard-button">Vai alla scheda</txp:permlink>
</div><!-- post -->
</div><!-- right-box -->
</div><!-- product-big -->

Offline

Board footer

Powered by FluxBB