Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-10-29 23:40:37

otti
Member
From: Australia
Registered: 2008-04-16
Posts: 75
Website

Display articles by category

I’m developing a website with a view sections but many categories (only one article per category). My page has an article tag <txp:article form="static_text" limit="1" />
and the form “static_text” looks as follows

<!-- Display section pages i.e. about -->
<txp:if_category name="">
<h3><txp:title /></h3>
<txp:body />
</txp:if_category>
<!-- Display category pages i.e. about?=quality-->
<txp:if_category name="quality">
<txp:article_custom category="quality">
<h3><txp:title /></h3>
<txp:body />
</txp:article_custom>
</txp:if_category>
<txp:if_category name="safety-hse">
<txp:article_custom category="safety-hse">
<h3><txp:title /></h3>
<txp:body />
</txp:article_custom>
</txp:if_category>
etc

The first part in the form is responsible to display articles without a category i.e. about (section). The next declarations show each article with a certain category name. It works but shouldn’t there be an easier way to declare the form content i.e. <txp:category /> instead of the written out category name for each category (tried this but won’t display the article), which ends up being a very long list and easy scalability is not given.

Any help would be much appreciated.
otti

Offline

#2 2012-11-02 13:23:59

etc
Developer
Registered: 2010-11-11
Posts: 5,397
Website GitHub

Re: Display articles by category

You mean this does not work?

<txp:if_category>
  <txp:article_custom category='<txp:category />'>
    <h3><txp:title /></h3>
    <txp:body />
  </txp:article_custom>
<txp:else />
  <h3><txp:title /></h3>
  <txp:body />
</txp:if_category>

Offline

#3 2012-11-03 00:14:15

otti
Member
From: Australia
Registered: 2008-04-16
Posts: 75
Website

Re: Display articles by category

Thanks so much etc.

I think the doubling up of the category was the culprit. It’s working now with your help.

Many thnaks again.
otti

Offline

Board footer

Powered by FluxBB