Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
#1 2020-01-04 19:30:56
- Myusername
- Member
- Registered: 2019-12-12
- Posts: 96
How to check if article_custom got results?
I need to check if the <txp:article_custom>
tag returned results. Something like:
<txp:article_custom category="myCategory">
If you have one or more articles
<txp:else/>
If you don't have articles
</txp:article_custom>
What is the easiest way to get there?
Offline
#2 2020-01-04 19:52:15
- colak
- Admin
- From: Cyprus
- Registered: 2004-11-20
- Posts: 8,470
- Website
Re: How to check if article_custom got results?
Hi,
I’m sure that there is a more modern way using the evaluate
tag but traditionally, you could try
<txp:variable name="hasarticles"><txp:article_custom category="myCategory" limit="1" /></txp:variable>
<txp:if_variable name="hasarticles" value="">
the category has no articles
<txp:else/>
It has articles
</txp:if_variable>
Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.
Offline
#3 2020-01-04 20:01:04
- colak
- Admin
- From: Cyprus
- Registered: 2004-11-20
- Posts: 8,470
- Website
Re: How to check if article_custom got results?
I just checked the docs. This may also work, although I have very limited experience with the tag:
<txp:evaluate test='<txp:article_custom category="myCategory" limit="1" />'>
has articles
<txp:else />
has no articles
</txp:evaluate>
alternatively:
<txp:evaluate test="myCategory">
has articles
<txp:else />
has no articles
</txp:evaluate>
I think that using this tag you can even delete the else
statement and it will only return content if there is one.
Yiannis
——————————
neme.org | hblack.net | State Machines | NeMe @ github
I do my best editing after I click on the submit button.
Offline
#4 2020-01-04 20:22:16
- etc
- Developer
- Registered: 2010-11-11
- Posts: 4,081
- Website
Re: How to check if article_custom got results?
Myusername wrote #320829:
I need to check if the
<txp:article_custom>
tag returned results. … What is the easiest way to get there?
What you suggest is working for me:
<txp:article_custom category="myCategory" limit="1">
If you have one or more articles
<txp:else />
If you don't have articles
</txp:article_custom>
Online
#5 2020-01-04 20:35:30
- Myusername
- Member
- Registered: 2019-12-12
- Posts: 96
Re: How to check if article_custom got results?
etc wrote #320833:
What you suggest is working for me
It is true! I should be doing something wrong initially. Thanks.
Thanks for the alternative ways, colak.
Offline
Pages: 1