Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-12-30 15:17:59

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Different output depending on number of articles in a category

Have the following code, with which I would like to:

1. Check how many articles there are in a given category
2. Change the presentation based on how many articles, for example, if there is one article in a category, display the title and body. If more than one article in a category, display the title and excerpt, then a “read on” link
3. If the user is in the individual article page, and there is more than one article in the category, then display a list of the other category articles under the individual article

I just can’t seem to find a way to find the number of articles. Code:

<txp:if_section name=“section_name”>

<txp:if_individual_article>
<!— article page: display the article – No problems here —>
<txp:article limit=1 />
</txp:if_individual_article>

<txp:if_article_list>
<txp:if_category>
<!— category page: display the articles —>
<!— But how to count the articles? —>
<!— Need to count the articles, then have an if/else for displaying a list of articles or the only article —>

<txp:article form=“article_list” limit=“100” />

<txp:else />
<!— section page: display the first article – No problems here —>
<txp:article status=“sticky” limit=1 />

</txp:if_category>
</txp:if_article_list>
</txp:if_section>

Offline

#2 2006-12-30 16:33:56

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

Re: Different output depending on number of articles in a category

jstubbs wrote:

I just can’t seem to find a way to find the number of articles.

mdn_count does that for you


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

Offline

#3 2006-12-31 14:02:07

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: Different output depending on number of articles in a category

Thanks Colak I will check the plugin you mention. I would have to check the article count first, then adjust the presentation….

Any ideas how I could do the following?

<txp:if_article_list>
<txp:if_category>
<!— category page: display the articles —>
<!— count the articles, then have an if/else for displaying a list of articles or the only article —>

1. Article count in the category in question
IF article_count ==1, then show the full article
<txp:article form=“article_list” limit=“100” />
ELSE show the list of articles
<txp:article form=“article_list” limit=“100” />

The next else is if we are in a Section page, not in a category page
<txp:else />
<!— section page: display the first article – No problems here —>
<txp:article status=“sticky” limit=1 />

</txp:if_category>
</txp:if_article_list>

Offline

Board footer

Powered by FluxBB