Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-02-22 12:27:16

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,079
Website

Merging two category types into one list?

I was looking at outputting the combination of article and image categories in one list. The following does not work:

<txp:category_list type='article, image' wraptag='ol' break='li' sort='title desc' />

Any reason why that would not be possible? Same issue with <txp:category /> and <txp:if_category />, btw.
I ended up building my list more manually:

<ol>
<txp:category_list type='article' break='li' sort='title desc' />
<txp:category_list type='image' break='li' sort='title desc' />
</ol>

~~~

While investigating this, I found out that <txp:category type='' /> actually works — that seems undocumented. That was a sort of blessing.
My default page template:

<!-- stuff-->
<txp:if_category> <!-- do something for categories -->
<txp:else />
<!-- other stuff -->
<ol>
<txp:category_list type='article' break='li' sort='title desc' />
<txp:category_list type='image' break='li' sort='title desc' />
</ol>
</txp:if_category>

The links for the image category would not work correctly, loading the default “front“ page instead of the category page. As soon as I changed my opening category tag to <txp:category type=''>, those links started working. Which is logical of course, the default value for type being article.

Edit: correct some markup error, thanks for the pointer GugUser.

Last edited by phiw13 (2017-02-23 04:15:06)


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#2 2017-02-22 17:22:03

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,529
Website GitHub Twitter

Re: Merging two category types into one list?

Hi

Have you tryed smd_query ?

Offline

#3 2017-02-23 01:46:48

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,079
Website

Re: Merging two category types into one list?

Dragondz wrote #304189:

Hi

Have you tryed smd_query ?

No I haven’t considered that; honestly. A bit of overkill for my humble needs in this case. But I was more puzzled by the fact that the type attribute only supported one value.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#4 2017-02-23 03:42:13

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: Merging two category types into one list?

I don’t understand what you are doing with…

<txp:category>
<txp:else />
<txp:category>

Should it be <txp:if_category>?

Offline

#5 2017-02-23 04:13:43

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,079
Website

Re: Merging two category types into one list?

GugUser wrote #304201:

Should it be <txp:if_category>?

You are correct sir! I’ll update the snippet in my OP.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

#6 2017-02-23 09:14:28

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

Re: Merging two category types into one list?

phiw13 wrote #304200:

I was more puzzled by the fact that the type attribute only supported one value.

I guess it’s because of homonyms, which are not allowed within a type, but possible across two types. If you have both article and image categories called sunrise, and want to display their subcategories tree, this standard construction will not work:

<txp:category_list children="0" parent="sunrise" exclude="sunrise" type="article, image" wraptag="ul" break="li">
    <txp:category title="1" link="1" />
    <txp:category_list children="0" parent='<txp:category />' exclude='<txp:category />' wraptag="ul" break="li">
        <txp:category title="1" link="1" />
    </txp:category_list>
</txp:category_list>

This could somehow be amended, but I think that mixing different types of objects is generally error-prone.

Offline

#7 2017-02-23 09:27:12

phiw13
Plugin Author
From: Japan
Registered: 2004-02-27
Posts: 3,079
Website

Re: Merging two category types into one list?

etc wrote #304205:

I guess it’s because of homonyms, which are not allowed within a type, but possible across two types. If you have both article and image categories called sunrise, and want to display their subcategories tree, this standard construction will not work:

Ok, yeah I can see that being a problem indeed. Thanks for explaining.


Where is that emoji for a solar powered submarine when you need it ?
Sand space – admin theme for Textpattern

Offline

Board footer

Powered by FluxBB