2005-10-28 12:50:43

Case
Member
beta
From: UK
Website

How to list articles in the same category as the current article

I struggled for a while to find a solution for how to list links to all other articles in the same category as the current article being viewed. Here’s how it can be accomplished using just the built in TextPattern tags.

In an article form insert:

<txp:if_article_category name="yourcategory" number="1">
<ul>
<txp:article_custom form="sub" category="yourcategory" sortby="Posted" sortdir="asc" />
</ul>
</txp:if_article_category>
</code>
And then your article form (in this case called 'sub') for listing links to other articles can be something like this:
<code>
<li><txp:permlink><txp:title /></txp:permlink></li>

Last edited by Case (2005-10-28 12:52:33)


Forget your dreams

Offline

 

2005-10-29 01:43:54

rsilletti
Moderator
nu
Real name: Rick Silletti
From: Yellowstone Ntl Park

Re: How to list articles in the same category as the current article

Thanks Case, <code><txp:if_article_category></code> is difficult to describe. This example puts it in context well.

Offline

 

2005-10-31 01:16:27

hippos
New Member
alpha

Re: How to list articles in the same category as the current article

Maybe off the topic but these examples are great for starters like me, thanks to everyone that contributes :)

Offline

 

2006-12-29 19:34:58

linkingarts
Member
beta

Re: How to list articles in the same category as the current article

Seeing as it’s been over a year since the last post to this thread, here’s hoping I’ll get a response!

I’d like to do the above but without having to specify my category, but default to a variable. i.e. “yourcategory” in all cases above would be “currentcategory”. Or to put it another way, “$thiscategory”. Can I do that? Do I need to access $GLOBALS somehow (can that even be done any longer)?

Ideally the code would be something like

<txp:if_article_category name="<txp:category1 />"> <ul> <txp:article_custom form="related_articles" sortby="Title" sortdir="asc" section="performers" name="<txp:category1 />" /> </ul> </txp:if_article_category>

but that doesn’t work since the nested tags get processed as HTML (or ?)…

thx folks!

Last edited by linkingarts (2006-12-29 20:49:32)

Offline

 

2006-12-29 20:53:45

tgermer
New Member
alpha
Real name: Tim Germer
From: Portland, Oregon
Website

Re: How to list articles in the same category as the current article

I think pointing you to http://forum.textpattern.com/viewtopic.php?id=18593 would be helpful – I believe asy_wondertag can help you do that.

Offline

 

2006-12-29 21:41:32

linkingarts
Member
beta

Re: How to list articles in the same category as the current article

sweet, thanks! Seems to be working (with a bit of tweaking)

Offline

 

2009-06-14 07:50:01

Vienuolis
Member
delta
Real name: Vladas Palubinskas
From: Vilnius, Lithuania
Known languages: lt, ru, fr, en
Website

Re: How to list articles in the same category as the current article

Sorry, I’m novice, thus I don’t quite catch the reason of additional form and why to name each category/subcategory. My code is simple:

<code><txp:if_article_category><txp:recent_articles limit=“10” break=“dd” label=“Other articles in the series <txp:category1 />:” labeltag=“dt” wraptag=“dl class=‘toc’” /></txp:if_article_category></code>

But I am looking for structured TOC of a current category (like in Drupal Book), e.g. how to display contents of subcategory (Category2) with only one link to the parent category1. Or a list of articles in a current category1, if the current article does rest in a subcategory.

Offline

 

2009-06-14 08:02:33

colak
Admin
omega
Real name: Yiannis
From: Cyprus
Known languages: el, en
Website

Re: How to list articles in the same category as the current article

Hi Vladas,

Welcome to txp

For a list of articles in current category1 check out the related_articles tag. Also check out this Txp Tip for your sub-category question.

Offline

 

Powered by FluxBB