Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2020-01-04 19:30:56
- Myusername
- Member
- Registered: 2019-12-12
- Posts: 165
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
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
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 | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.
Offline
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>
Offline
#5 2020-01-04 20:35:30
- Myusername
- Member
- Registered: 2019-12-12
- Posts: 165
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