Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2022-06-09 16:15:18

sambooth74
Member
From: Leeds, England
Registered: 2020-11-24
Posts: 20
Website

Bug in category_list when using parent, children and break attributes?

On my home page, I want to show the latest 5 articles from 3 “featured categories”.

It is important to include articles from subcategories as well, because in my site structure, I only assign articles to subcategories. The top-level categories have zero articles.

- Fruits     (0 articles)
-- Apples    (5 articles)
-- Bananas   (6 articles)
- Vegetables (0 articles)
-- Carrots   (7 articles)
-- Onions    (8 articles)
- Birds      (0 articles)
-- Magpies   (3 articles)
-- Finches   (5 articles)

My strategy is:
1. Use category_list and the category attribute to produce a list of my 3 categories
2. Build a comma-separated list of child categories using category_list
3. Use article_custom to display the list of articles

This is fiddly due to the nested tags, but I think it should be possible.

On my page I have:

<txp:category_list categories="fruits,vegetables,birds" form="mycustomform" />

The contents of mycustomform are:

<txp:article_custom category='<txp:category_list parent=''<txp:category />'' children="3" break="," />' wraptag="ul" break="li" limit="5" frontpage="1" />

This didn’t work, so I tried the inner tag by itself, for one of the categories, to see how it was being parsed:

<txp:category_list parent='<txp:category />' children="3" break=","><txp:category /></txp:category_list>

I had expected this to return fruits,apples,bananas but it actually returned fruitsapples,bananas

Notice the comma is missing between the parent item and the first child. I think this is a bug.

Can anybody reproduce this issue please? Is there an easier way to achieve my goal? Have I found a bug?

Many thanks

Last edited by sambooth74 (2022-06-09 16:16:47)

Offline

#2 2022-06-09 16:32:57

sambooth74
Member
From: Leeds, England
Registered: 2020-11-24
Posts: 20
Website

Re: Bug in category_list when using parent, children and break attributes?

After spending an hour on this, and then writing up the issue, I think I solved my own problem 5 minutes later. You aren’t supposed to use the parent and children attributes of category_list at the same time….. When I removed the children attribute, my issue was resolved.

I still feel like my solution is quite complex, so if anyone has a better idea, please let me know!

Many thanks

Last edited by sambooth74 (2022-06-09 16:33:16)

Offline

#3 2022-06-09 17:11:50

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,742
Website

Re: Bug in category_list when using parent, children and break attributes?

If I’ve understood your structure properly, you should be able to simplify it to this:

<txp:variable name="featured_cats" trim>
   <txp:category_list parent="fruits,vegetables,birds" exclude="fruits,vegetables,birds" break=","><txp:category /></txp:category_list>
</txp:variable>

<txp:article_custom category='<txp:variable name="featured_cats" />' limit="5" sort="Posted desc" wraptag="ul" break="li">
    <txp:permlink><txp:title /></txp:permlink><txp:category1 wraptag=" (<+>)" />
</txp:article_custom>

The first part outputs a comma-separated list of all the parents and children of the specified parent categories excluding the parents and saves that in a variable.

The second part then lists the 5 most recent articles that appear in any of the previously determined sub-categories.


TXP Builders – finely-crafted code, design and txp

Offline

#4 2022-06-09 18:58:28

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,742
Website

Re: Bug in category_list when using parent, children and break attributes?

Hmm, on second thoughts maybe you did mean the 5 most recent articles from each of your 3 parent categories, i.e. 3 × 5 articles.

Then it would be almost like you have it excerpt that you can use the exclude attribute here too:

<txp:category_list categories="fruits,vegetables,birds" break="">
    <!-- category heading -->
    <txp:category title wraptag="h3" />
    <!-- five most recent articles in the respective sub-categories -->
    <txp:article_custom category='<txp:category_list parent=''<txp:category />'' exclude=''<txp:category />'' break=","><txp:category /></txp:category_list>' limit="5" sort="Posted desc" wraptag="ul" break="li">
        <txp:permlink><txp:title /></txp:permlink>
    </txp:article_custom>
</txp:category_list>

TXP Builders – finely-crafted code, design and txp

Offline

#5 2022-06-09 19:05:44

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,742
Website

Re: Bug in category_list when using parent, children and break attributes?

One further note: with both of the above you will in fact get the same output without the exclude attribute because as you write …

The top-level categories have zero articles.

… which means: without exclude attribute, the article_custom tag will also look for articles in the parent categories but as there aren’t any articles assigned to them, it will only return articles from the child categories.


TXP Builders – finely-crafted code, design and txp

Offline

#6 2022-06-09 21:26:28

sambooth74
Member
From: Leeds, England
Registered: 2020-11-24
Posts: 20
Website

Re: Bug in category_list when using parent, children and break attributes?

It’s good to hear from a knowledgeable person that my solution is sensible, many thanks!

Offline

#7 2022-06-10 09:41:50

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

Re: Bug in category_list when using parent, children and break attributes?

sambooth74 wrote #333566:

Have I found a bug?

Not this time. Using children="3" with non-hierarchical wraptag/break (like ul/li) simply has no much sense.

Online

Board footer

Powered by FluxBB