Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
How to limit number of articles per section in article custom?
Hello!
I’m trying to figure out how to dynamically (not multiple instances of article custom with different sections) list two articles from each section with article custom.
Any suggestions appreciated.
/Mats
Offline
#2 2011-09-25 11:11:04
- redbot
- Plugin Author
- Registered: 2006-02-14
- Posts: 1,410
Re: How to limit number of articles per section in article custom?
Hi,
if I understood it correctly you could use the plugin rah_repeat this way (just a barebone example – not tested):
<txp:rah_repeat value='<txp:section_list break="," />'>
<txp:article_custom section='<txp:rah_repeat_value />' limit='2'>
<txp:section title="1" />
</txp:article_custom>
</txp:rah_repeat>
Offline
Re: How to limit number of articles per section in article custom?
Thanks redbot!
Not quite what i’m after but i wasn’t clear enough.
I want the list to output the most recent articles from a number of sections but only two articles from each section.
Or in other words:
The two most recent articles from a bunch of sections.
Offline
Re: How to limit number of articles per section in article custom?
Try redbot’s code again, but replace the central <txp:section title="1" />
with <txp:permlink />
(that may have been what he actually meant to write).
You should be able to do the same without rah_replace, though:
<txp:section_list sections="bunch,of,section-names" break="">
<txp:article_custom section='<txp:section />' limit="2">
<txp:permlink />
</txp:article_custom>
</txp:section_list>
If you prefer, you can not define an explicit bunch of sections by leaving out the sections
attribute and instead using exclude="sections,to,exclude"
to omit certain sections that should not appear. See txp:section_list in the textbook.
TXP Builders – finely-crafted code, design and txp
Offline
#5 2011-09-25 15:21:45
- redbot
- Plugin Author
- Registered: 2006-02-14
- Posts: 1,410
Re: How to limit number of articles per section in article custom?
Mats wrote:
Thanks redbot!
Not quite what i’m after but i wasn’t clear enough.
I want the list to output the most recent articles from a number of sections but only two articles from each section.
Or in other words:
The two most recent articles from a bunch of sections.
Yes Mats, that was exactly what my example was meant to do.
Here is the same snippet with comments to make it more clear:
<txp:rah_repeat value='<txp:section_list break="," />'> <!-- this takes a comma-separated list of all sections (of course you can limit it as you like - see the tag reference for section_list) and for each section applies the code below-->
<txp:article_custom section='<txp:rah_repeat_value />' limit='2'> <!--this generates - for each section called above - the first two articles (see limit='2')-->
<txp:section title="1" /> <!--this generates the title for each article - of course you'll want to adapt it to your needs - this is just a barebone example-->
</txp:article_custom>
</txp:rah_repeat>
I hope it’s more clear now. Or maybe I have totally misunderstood your question?
edit Oh yes. Jakob is right. You can obtain the same result using only standard txp tags: ignore my code above and use Jakob’s one!
edit 2 ..and yes , Jakob is right again, I meant <txp:permlink><txp:title /></txp:permlink>
instead of <txp:section title="1" />
;-)
Last edited by redbot (2011-09-25 15:35:18)
Offline
Re: How to limit number of articles per section in article custom?
Thanks for helping out!
You guys <txp:rock/>!
Best regards
Mats
Update: I wanted a different sorting. The code above generates articles paired together by section. So i pulled out the article id:s instead of article titles in to another article custom where the articles could be resorted. Textpattern is a nimble beast!
Last edited by Mats (2011-09-25 20:06:42)
Offline