Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2024-10-25 18:38:02
- joanlafulla_Almas
- Member
- Registered: 2011-02-25
- Posts: 20
Group Article results (into two groups) and place a div in the middle
I need something like this…
<div class=“group”>
<article id=“1” />
<article id=“2” />
</div>
<— …an extra div between the two result sets —>
<div class=“featured_article”>A featured article</div>
<div class=“group”>
<article id=“3” />
<article id=“4” />
</div>
I’m trying something like this…
<txp:article limit=“12” breakby=“6” break=“div” breakclass=“group”>
But this only manages to group the results into two groups.
Is there a way to include content (for example a featured article) between the two groups?
Thanks
Offline
Re: Group Article results (into two groups) and place a div in the middle
This is a typical case for the offset
and limit
attributes of the txp:article tag:
<!-- 2 regular articles -->
<txp:article limit="2" wraptag="div" class="group" form="my_article_form" />
<!-- featured article -->
<txp:article_custom id="123" form="my_featured_article_form" />
<!-- 2 more regular articles starting from article 3 -->
<txp:article limit="2" offset="2" wraptag="div" class="group" form="my_article_form" />
Would that help?
TXP Builders – finely-crafted code, design and txp
Offline
#3 2024-10-27 08:14:44
- joanlafulla_Almas
- Member
- Registered: 2011-02-25
- Posts: 20
Re: Group Article results (into two groups) and place a div in the middle
Thanks for your reply Jakob and I’m sorry I didn’t get to try it before.
The solution doesn’t quite work for me. I probably didn’t explain the use case correctly.
I have a very high number of results. I have, for example, 300 results, and I show 12 results on each page (I have pagination). What I’m looking for is that within each page, with 12 results, I can put a featured article after the 6th result.
That is:
- Show 6 results
- Show a featured article
- Show 6 results
And, that on the next page I can continue showing the next 12 results with the same scheme (a featured article in the middle of the 12 results).
With the solution you propose I can include the featured article, but the pagination doesn’t work for me. The two articles that I show after the featured article are shown again on page 2.
That’s the reason why I initially tried to “break” the same query (txp:article) into two groups with the “breakby” function, but then I didn’t know how to include a featured article between the two groups.
Last edited by joanlafulla_Almas (2024-10-27 08:21:44)
Offline
Re: Group Article results (into two groups) and place a div in the middle
Is it the same featured article on every page?
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Group Article results (into two groups) and place a div in the middle
Possibly, setting pageby="4"
in jacob post (or rather pageby=2*limit
) in the first article tag fixes the problem? There are more flexible solutions too, involving breakform
, if more than 2 article blocks are needed.
Offline
#6 2024-10-27 17:43:58
- joanlafulla_Almas
- Member
- Registered: 2011-02-25
- Posts: 20
Re: Group Article results (into two groups) and place a div in the middle
Bloke wrote #338068:
Is it the same featured article on every page?
I first thought of having a different featured article on each page. But if that’s too complicated, I think the same featured article for all pages would be fine.
Offline
#7 2024-10-27 18:00:04
- joanlafulla_Almas
- Member
- Registered: 2011-02-25
- Posts: 20
Re: Group Article results (into two groups) and place a div in the middle
etc wrote #338069:
Possibly, setting
pageby="4"
in jacob post (or ratherpageby=2*limit
) in the first article tag fixes the problem? There are more flexible solutions too, involvingbreakform
, if more than 2 article blocks are needed.
I tried but doesn’t work for me. This is the result:
Page 1:
- Article 1, Article 2
- FEATURED ARTICLE
- Article 3, Article 4
Page 2:
- Article 5, Article 6
- FEATURED ARTICLE
- Article 5, Article 6 (…error…)
And this is the code simplified:
<txp:article limit=“2” pageby=“4”>
<article>
<txp:excerpt />
</article>
</txp:article>
<txp:article_custom id=“5” />
<txp:article limit=“2” offset=“2”>
<article>
<txp:excerpt />
</article>
</txp:article>
Offline
Re: Group Article results (into two groups) and place a div in the middle
joanlafulla_Almas wrote #338070:
I first thought of having a different featured article on each page. But if that’s too complicated, I think the same featured article for all pages would be fine.
You could take a look at smd_featured as it might offer some useful functionality to work with your desired page structure.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#9 2024-10-27 19:25:53
- joanlafulla_Almas
- Member
- Registered: 2011-02-25
- Posts: 20
Re: Group Article results (into two groups) and place a div in the middle
Bloke wrote #338072:
You could take a look at smd_featured as it might offer some useful functionality to work with your desired page structure.
I’ve tried the plugin, but I can’t get the desired result.
I need the featured article to be outside the normal flow of articles. That is:
- 1st row: Article 1 / Article 2
- 2nd row: Featured article (outside the normal flow). It could also be, for example, an advertising banner instead of a featured article. But the key is that I want to insert it in the middle of the normal results list.
- 3rd row: Article 3 / Article 4
I would mark the featured article with a <txp:custom_field> “featured”, and then I would perform a <txp:article_custom> query of the article with the custom_field “feature”. And then I would like to include the result of this query in the middle of the normal flow of results list.
Offline
Re: Group Article results (into two groups) and place a div in the middle
joanlafulla_Almas wrote #338073:
I need the featured article to be outside the normal flow of articles.
Okay, no worries. I thought you were going with two article tags to manage the two sets of results per page, which would let you more easily add the featured article tag in between them.
If you’re trying to do it all in one article tag then yeah, the plugin probably isn’t going to help.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
#11 2024-10-27 19:41:31
- joanlafulla_Almas
- Member
- Registered: 2011-02-25
- Posts: 20
Re: Group Article results (into two groups) and place a div in the middle
Bloke wrote #338074:
Okay, no worries. I thought you were going with two article tags to manage the two sets of results per page, which would let you more easily add the featured article tag in between them.
If you’re trying to do it all in one article tag then yeah, the plugin probably isn’t going to help.
Yes, I think two result groups don’t work because they create a lot of problems with pagination. I think it’s better to have one result group and maybe using the “break” to divide it into two subgroups (but it’s still a single query) and then I have the problem of putting additional content (featured article, ad banner…) in between the two subgroups.
I don’t know if this type of structure is possible.
Offline
Re: Group Article results (into two groups) and place a div in the middle
It looks like a weird bug, will check, thanks for testing. Another option is to create a misc form, say twoart
:
<div class="group"><+></div>
Then you should be able to call
<txp:article limit="4" breakby="2" breakform="twoart" break='<txp:article_custom id="5" />' />
Offline