Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
List articles' categories without duplicates
Hi,
I will like to create a category-list of category2 from articles from a specific section with a specific custom-field value.
In the end, the result should be a list of categories (category2) from articles and that there will be no duplicates.
Of course this doesn’t have to be made with the <txp:category_list />
tag, but I don’t know how to remove duplicates by using <txp:article_custom />
I will like to get help with this please.
Something like:
<ul>
<txp:category_list section='<txp:section />'
categories='<txp:article_custom section="mySection" customfieldname="value" limit="999"><txp:category2 /><txp:if_last_article><txp:else />,</txp:if_last_article></txp:article_custom>' wraptag="" break="">
<li><txp:category title="1" link="1" /></li>
</txp:category_list>
</ul>
Offline
#2 2012-03-18 23:07:46
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: List articles' categories without duplicates
Gil, a while back jakob has posted a solution in a thread with a similar topic, see his code comment “remove any duplicates from more texts” (where “more texts” is the variable “moretexts” above).
Last edited by uli (2012-03-18 23:08:25)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: List articles' categories without duplicates
In this case, couldn’t you do something simpler with article_custom and if_different. Off the top of my head:
<ul>
<txp:article_custom section="mySection" customfieldname="value" limit="999" sort="Category2 asc">
<txp:if_different><li><txp:category name='<txp:category2 />' title="1" link="1" /></li></txp:if_different>
</txp:article_custom>
</ul>
You could also do it your way and put the if_different construction into your category_list code (remember to add the sort attribute).
TXP Builders – finely-crafted code, design and txp
Offline
Re: List articles' categories without duplicates
Thanks Uli & Jakob!
I used Jakob’s code and it works :)
I wasn’t familiar with if_different
, that’s cool!
Offline