Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2010-04-14 12:20:14
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
List of articles with current category
I want a list of articles with the same category as the current article.
I made a form like this:
<txp:if_category>
<txp:asy_wondertag>
<txp:article_custom category="<txp:category />" />
</txp:asy_wondertag>
<txp:article />
</txp:if_category>
But I get every article, not just the ones with the current category. What’s wrong?
Offline
Re: List of articles with current category
hi bmwg
asy wondertag is not needed if you are using txp 4.2+
you can achieve this by using native tags
<txp:related_articles match='<txp:category />' limit="10" />
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
Re: List of articles with current category
Hi
using a recent txp installation (4.0.7 or 4.0.8 or above) you can do nested tag without asy_wondertag.
Here is a code without asy_wondertag (your error is using txp:category instead od txp:article_category :
<txp:article>
<txp:if_article_category>
<txp:article_custom category='<txp:article_category />' />
</txp:if_article_category>
<txp:body />
</txp:article />
You can also use txp:related-article
Cheers.
Offline
#4 2010-04-14 13:06:42
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
Re: List of articles with current category
Dragondz, your code also returns every article no matter which category is selected.
Offline
Re: List of articles with current category
bmwg wrote:
Dragondz, your code also returns every article no matter which category is selected.
It’s using a fictitious <txp:article_category />
tag :-)
You’ll need to match category1 and/or category2 for it to work as you expect. I’d go with <txp:related_articles />
as it does it all for you; although I don’t know if the match
attribute works like colak intends… I’ve never used it but I think it only accepts Category1
or Category2
as parameters — you can probably omit it and get what you’re after. Someone can confirm this (or put me in my place!) I’m sure.
Last edited by Bloke (2010-04-14 13:29:38)
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: List of articles with current category
hoooo
Apologise for my mistake the code must be:
<txp:article>
<txp:if_article_category>
<txp:article_custom category='<txp:category1 />' />
</txp:if_article_category>
<txp:body />
</txp:article />
And like said before txp:related_article is better solution and use it like this(in individual article contexte):
<txp:related_article />
<txp:article />
you can see txp:related_article here
Last edited by Dragondz (2010-04-14 13:49:46)
Offline
#7 2010-04-14 14:08:28
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
Re: List of articles with current category
Thanks.
I’m not sure if txp:related_article is the right thing for me.
Here’s what I want to do:
I have a list of categories. They act as product groups. And in each category are articles which can be of one of 3 types.
Type 1 is a product.
Type 2 is some kind of information material.
Type 3 is the default article for the product group.
So if I have a product group “tables” it would contain some articles of type 1 (like “Table Model Bjoern”) some articles of type 2 (like “General things about tables”) and one article of type 3 (Thats the text i want to see if only the category and no other article is selected).
I want to use two lists. One for the actual products and one for information material which is the same for the whole product group. So I thought I’d check for each article whether “tables” (or whatever category is selected) is it’s category1 or category2. If it’s 1 the article title goes in the product list. If it’s 2 it goes in the information material list.
I’m not sure though how to distinct the default article from the other two types.
Offline
Re: List of articles with current category
Maybe you’re over complicating things
Did you think of using
Type 1 is a product. – the article body
Type 2 is some kind of information material. – the excerpt
Type 3 is the default article for the product group. – a sticky
Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
#9 2010-04-14 16:15:53
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
Re: List of articles with current category
Thanks, but product and information material are not on the same level in the hierarchy. The information material can be the same for many products of the same product group. (A blue table and a red table are two different articles but they might share the same data sheet) There’s also more than one piece of information material for every actual product. And I need body and excerpt for what they are.
But I’ll look into the thing with the sticky article.
Offline
#10 2010-04-14 17:40:25
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: List of articles with current category
bmwg wrote:
So I thought I’d check for each article whether “tables” (or whatever category is selected) is it’s category1 or category2. If it’s 1 the article title goes in the product list. If it’s 2 it goes in the information material list.
Not sure if I understand you correctly, but would this do what you want?
<txp:if_category>
<h3>Product list</h3>
<txp:article>
<txp:if_article_category number="1" name='<txp:category />'>
<txp:permlink><txp:title /></txp:permlink>
</txp:if_article_category>
</txp:article>
<h3>Information material list</h3>
<txp:article>
<txp:if_article_category number="2" name='<txp:category />'>
<txp:permlink><txp:title /></txp:permlink>
</txp:if_article_category>
</txp:article>
</txp:if_category>
Keep in mind that if you have a large number of articles this might not be so efficient, because the code needs to check all articles, even though only some will be displayed.
Offline
#11 2010-04-14 18:07:42
- bmwg
- Member
- Registered: 2010-04-06
- Posts: 39
Re: List of articles with current category
Thanks a lot!
That’s exactly what I’m after. I’m new to textpattern and have my troubles with even such basic tasks.
There’s not so many articles so I don’t think efficiency is a problem.
Offline
#12 2010-04-14 18:22:42
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: List of articles with current category
bmwg wrote:
…even such basic tasks.
It’s not that basic ;) what you were trying to do is not something the average user will need.
Offline