Go to main content

Textpattern CMS support 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: 256
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 Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
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.

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

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)

Offline

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

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
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
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Group article two by two

My solution is dynamic. :)

Offline

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

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
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
Registered: 2006-08-15
Posts: 4,303

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
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

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.

Offline

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

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

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.

Offline

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

wornout
Member
From: Italy
Registered: 2009-01-20
Posts: 256
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

#11 2012-08-30 15:26:55

etc
Developer
Registered: 2010-11-11
Posts: 5,028
Website GitHub

Re: Group article two by two

You are using wrong selectors: either wrap the content of slide form in <article> tag, or replace query="//article[position() mod 2=1]" by

query="//div[@class='product-big'][position() mod 2=1]"
and {following-sibling::article[1]} by {following-sibling::div[1]}.

Edit: and check if {following-sibling::div[1]} is well wrapped in braces, your code lacks the opening one.

Last edited by etc (2012-08-30 15:31:37)

Offline

#12 2012-08-30 15:52:58

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

Re: Group article two by two

Thanks! Everything works!

Offline

Board footer

Powered by FluxBB