Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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

#2 2010-04-14 12:40:10

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,397
Website GitHub Mastodon Twitter

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.

Online

#3 2010-04-14 12:41:52

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

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

#5 2010-04-14 13:28:23

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,502
Website GitHub

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.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#6 2010-04-14 13:42:17

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

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

#8 2010-04-14 15:49:38

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,397
Website GitHub Mastodon Twitter

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.

Online

#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

#13 2010-04-14 19:02:35

bmwg
Member
Registered: 2010-04-06
Posts: 39

Re: List of articles with current category

Ok, one more problem: each list gets filled with the right articles but as soon as I click on a link, the lists change. All that’s left is the link to the article I clicked and some text output saying that comments are disabled for this article (it gets output where the other list items are supposed to be). The article itself gets properly displayed at another div on the site though.

Offline

#14 2010-04-14 21:18:52

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: List of articles with current category

Ah OK, so you want to display the lists on an individual article page as well? Not just on a category page?
In the previous code example, we checked against the requested category (the category that is in the URL). When on an individual article page, which category should the article lists have? Should list one have the same category 1 as the individual article’s category 1, and ditto for list two and category 2?

Offline

#15 2010-04-15 06:18:22

bmwg
Member
Registered: 2010-04-06
Posts: 39

Re: List of articles with current category

This part of my page is basically three divs. 2 for the lists of products and info material and one for the actual content. I use your code for the two lists. And I have the following code on my content div:

<txp:if_individual_article>
 <txp:article form="myForm" limit="1"/>
<txp:else />
 <txp:article status="sticky" limit="1"/>
</txp:if_individual_article>

Since I use hierarchical categories for my product groups, the code displays the sticky article for the selected category (product group) with some general information about the group when no individual article is selected. And the product article once it is selected in the list. So far everything works fine.
However I don’t want the lists to change if the user doesn’t change the category. And I don’t understand this behaviour because your code fills the lists according to the current category. I don’t see how the category changes. After clicking on a list item I get url/section/category/article. (Before: url/section/category). Shouldn’t it still be the same category? That is shouldn’t the lists still load the same items even if I’m on an individual article page?

Offline

Board footer

Powered by FluxBB