Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2005-10-28 12:50:43

Case
Member
From: UK
Registered: 2004-02-25
Posts: 20
Website

[howto] 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

#2 2005-10-29 01:43:54

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: [howto] 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

#3 2005-10-31 01:16:27

hippos
New Member
Registered: 2004-05-26
Posts: 2

Re: [howto] 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

#4 2006-12-29 19:34:58

linkingarts
Member
Registered: 2006-06-18
Posts: 14

Re: [howto] 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

#5 2006-12-29 20:53:45

tgermer
New Member
From: Portland, Oregon
Registered: 2005-01-25
Posts: 7
Website

Re: [howto] 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

#6 2006-12-29 21:41:32

linkingarts
Member
Registered: 2006-06-18
Posts: 14

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

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

Offline

#7 2009-06-14 07:50:01

Vienuolis
Member
From: Vilnius, Lithuania
Registered: 2009-06-14
Posts: 310
Website GitHub GitLab Mastodon Twitter

Re: [howto] 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

#8 2009-06-14 08:02:33

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

Re: [howto] 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.


Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

Board footer

Powered by FluxBB