Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2012-02-13 19:55:17
- adamr
- Member
- Registered: 2011-08-01
- Posts: 10
Listing articles under category
Hi,
I’m trying to display a list of articles under a category, and an error message if there are no articles. So this is what I’ve got so far;
<h2>Category1</h2>
<txp:article_custom section=“section1” category=“category1” form=“form1” />
But obviously if there are no articles filed under ‘Category1’ then nothing appears. I’d like a message to appear with something like <p>Sorry, there are no articles under this category!</p>
Thanks for your help!
Edit: It would be even better for the message to say ‘Sorry, there are no articles under Category1!’. So it would display the category name as well.
Last edited by adamr (2012-02-13 19:57:26)
Offline
#2 2012-02-13 20:35:10
- milosevic
- Member
- From: Madrid, Spain
- Registered: 2005-09-19
- Posts: 390
Re: Listing articles under category
try chh_if_data plugin. It does exactly what you want:
<txp:chh_if_data>
<h3>Here's an article list</h3>
<txp:article_custom category="Nogo" />
<txp:else />
<p>article_custom had nothing to say.</p>
</txp:chh_if_data>
Last edited by milosevic (2012-02-13 20:36:06)
<txp:rocks/>
Offline
#3 2012-02-13 21:04:25
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Listing articles under category
Or without plugin:
<h2><txp:category title="1" /></h2>
<txp:variable name="has_articles" value='<txp:article_custom category=''<txp:category />'' limit="1">yes</txp:article_custom>' />
<txp:if_variable name="has_articles" value="">
<p>Sorry, there are no articles under <txp:category title="1" />!</p>
<txp:else />
<txp:article_custom section="section1" category='<txp:category />' form="form1" />
</txp:if_variable>
Offline
Re: Listing articles under category
Does the chh_if_data way only go to the database once? (Assuming that with two article_custom
tags Els’ solution makes two.)
Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker
Offline
#5 2012-02-13 21:40:44
- adamr
- Member
- Registered: 2011-08-01
- Posts: 10
Re: Listing articles under category
Hi guys, thanks for the quick reply. The server seems to currently be down for the plugin so I’d ideally like to try it without plugin. I’ve tried the code you gave me Els, but it doesn’t seem to work – I think because it may be in the wrong context? It’s currently on a main section page.
Offline
#6 2012-02-13 21:44:24
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Listing articles under category
adamr wrote:
I think because it may be in the wrong context? It’s currently on a main section page.
Yes, probably. You can try to wrap it in <txp:if_category>
tags.
Offline
#7 2012-02-13 22:02:09
- adamr
- Member
- Registered: 2011-08-01
- Posts: 10
Re: Listing articles under category
i lie, the plugin’s working now :-)
Offline
Pages: 1