Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2005-11-10 04:15:20
- boblet
- Member
- Registered: 2005-08-08
- Posts: 53
How do I make an article list using two categories?
Hi All,
I’m using Cat1 for article category (say ‘txp,server,ruby…’) and Cat2 for article language (say ‘en,ja’). On an archive page (listing articles) I’d like to specify a list of all posts from section="articles"
that are, say, category="txp"
AND category="en"
. It seems <txp:article listform="" />
won’t take a category attribute and txp:article_list />
only takes one category attribute. I tried:
<txp:article_custom category="txp" form="article_list" />
= articles from both languages are listed (obviously ;-)<txp:article_custom category="txp" form="if_en" />
with theif_en
form containing a<txp:if_category name="en">
= no articles listed<txp:article_custom form="if_txp_and_en" />
with theif_en
form containing a<txp:if_category name="txp,en">
= no articles listed<txp:if_category name="txp"><txp:article_custom category="txp" form="if_en" /></txp:if_category>
, and other variations withif_category
in the archive template = no articles listed (I assumeif_category
can only be used in an article template so it can get the category from the article, or I’m not understanding how to use it)
Next I tried installing chh_article_custom, which among other things allows the use of multiple categories to list articles: <txp:chh_article_custom category="txp,en" />
. Unfortunately this uses OR logic, so I got a listing of all articles that are either category=“txp” or category=“en”. What I’m after is AND; only articles that are in both txp and en categories. Unfortunately Takshaka (who wrote chh_article_custom) hasn’t been around here for about a year…
So, is there any way to make an article list using attributes like category="!txp,!en"
or cat1="txp" cat2="en"
? I assume this would involve either writing a plugin or hacking the source – are there any plugins out there that can do this that I’ve missed?
Any help greatly appreciated ;-)
peace – boblet
Offline
Re: How do I make an article list using two categories?
I think Mary’s example might help with this.
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
#3 2005-11-11 00:17:38
- boblet
- Member
- Registered: 2005-08-08
- Posts: 53
Re: How do I make an article list using two categories?
Hey TheBombSite,
thanks for the heads-up! Unfortunately I haven’t been able to get this to work. I tried <txp:article_custom section="portfolio" category="field(Category1, 'web'), field(Category2, 'en')" />
, and then remembering that article_custom
doesn’t support multiple categories yet, I also tried it with chh_article_custom
(which does). Stripping whitespace (category="field(Category1,'web'),field(Category2,'en')"
) also didn’t make any difference.
I guess I’ll have to wait for Mary to post it to the wiki – maybe with some more info I’ll know what I’m doing wrong and how to do it right.
peace – boblet
Offline
Re: How do I make an article list using two categories?
Well I don’t use it myself so I’m not really any help here but check out zem’s reply to Mary’s original comment.
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
#5 2005-11-11 15:48:57
- boblet
- Member
- Registered: 2005-08-08
- Posts: 53
Re: How do I make an article list using two categories?
With no easy answers forthcoming, I found a way:
I changed this line in chh_article_custom (which allows the use of multiple categories)
<code> $categories = ‘’; if (count($cats)) $categories = ‘ AND (’ . join(’ OR ‘, $cats) . ‘)’;</code>
to this
<code> $categories = ‘’; if (count($cats)) $categories = ‘ AND (’ . join(’ AND ‘, $cats) . ‘)’;</code>
and now a tag like <txp:chh_article_custom section="articles" category="server,en" limit="3" sortby="Posted" sortdir="desc" listform="dev-a-recent-articles" />
selects all articles that have both the categories server and en.
this randomly-changing-likely-words-until-it-works thing isn’t so hard after all. Unless there’s a lot of words in the plugin…
peace – boblet
Offline
Re: How do I make an article list using two categories?
Nice one! Did you check zem’s suggestion?
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
#7 2005-11-12 00:01:58
- boblet
- Member
- Registered: 2005-08-08
- Posts: 53
Re: How do I make an article list using two categories?
If you’re referring to the “Mary’s example” thread, there wasn’t any difference in Zem’s alteration wrt categories – it was a different way of calculating the date for sorting. I wonder if that technique would work in conjunction with chh_article_custom though. It’s possible the reason it doesn’t work with the default article_custom is because it can only take one category…
Offline
Re: How do I make an article list using two categories?
No. I think what zem is saying is that Mary’s example would only output articles if the timestamp was identical because she was using the date as the first sortby attribute. His example only extracts the date information but sorts by both categories. At least that’s the way I read it.
Last edited by thebombsite (2005-11-12 01:45:04)
Stuart
In a Time of Universal Deceit
Telling the Truth is Revolutionary.
Offline
#9 2005-11-12 09:59:04
- boblet
- Member
- Registered: 2005-08-08
- Posts: 53
Re: How do I make an article list using two categories?
Hrm, I thought it sorts by date and then the category “important”, whether it’s in Cat1 or Cat2. I did try it so either it doesn’t work for the categories attribute or I was doing something wrong. Probably the second option eh :-)
Actually Mary just replied to it today with a new approach, so I might check that out. No great need now I have a work-around, but might be a good trick to know…
Offline
#10 2005-12-07 07:11:13
- boblet
- Member
- Registered: 2005-08-08
- Posts: 53
Re: How do I make an article list using two categories?
Just a follow-up:
I initially hacked the chh_article_custom
plugin, but recently Takshaka came back from the dead and released a new version with AND|OR logic just for me
Offline