Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2010-01-10 17:35:22
- ploinkr
- Member
- From: Montreal
- Registered: 2007-12-06
- Posts: 83
category_list : displaying individual articles
Hi, I’m not a newbie anymore at Textpattern (at least I like to think so ;)) but I’m having a bit of a hard time figuring out this one: for my “archive” section, I have a list of month-based categories and for a few there’s going to be only one article related to one month. The basic idea would be that when you click on a category with just that one related article, it’d show that article only, using a basic article form (title, body).
I played with if_individual_article
but can’t get that to work. Any suggestion?
Thanks a bunch.
Offline
Re: category_list : displaying individual articles
ploinkr wrote:
I played with if_individual_article but can’t get that to work.
Article list is never an individual article page. Not even if there is only one article.
The basic idea would be that when you click on a category with just that one related article, it’d show that article only, using a basic article form (title, body).
So basically the article list page would show expanded view depending how many articles the category has.
First we need to count how many articles there are. You can use which ever method you want (vanilla, smd_query, smd_if, jmd_count, rah_function etc). Something like:
<txp:variable name="articles" value="0" />
<txp:article_custom limit="2" section='<txp:section />' category='<txp:category />'>
<txp:variable name="articles" value='<txp:php> echo variable(array("name" => "articles"))+1; </txp:php>' />
</txp:article_custom>
Now when we got a count:
<txp:if_variable name="articles" value="1">
<txp:article>
<txp:title />
<txp:body />
</txp:article>
<txp:else />
<txp:article>
<!--
Standard
-->
</txp:article>
</txp:if_variable>
If you want comment form and stuff on that singular article list, then you need to redirect instead to the real individual article. Something like (by using rah_function as helper). Of course this is wrapped inside the article tags instead title and body:
<txp:rah_function call="header" redirect='Location: <txp:permlink />' />
Offline
#3 2010-01-10 18:36:09
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: category_list : displaying individual articles
Here is a related TXP Tip. It’s about sections, but you can do the same for categories of course.
Offline
#4 2010-01-10 18:37:04
- ploinkr
- Member
- From: Montreal
- Registered: 2007-12-06
- Posts: 83
Re: category_list : displaying individual articles
Thanks a lot Jukka,
No wonder I couldn’t get it to work! I’ll look at your code very closely – reminds me that I should start to learn the basics of php.
Thanks again.
Offline