Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Plugin equivalent to if_article_custom?
Hi.
Is there a (recommended) plugin that will allow me to wrap something around article_custom
and do something if >0 articles are returned? That is, if 0 articles are returned then nothing happens and if 1 or more articles are returned, the contained command is run.
Thank you in advance.
Online
Re: Plugin equivalent to if_article_custom?
Hi Pete, You can do it using a variable
<txp:variable name="ac" value='<txp:article_custom category="your_category" section="your_section" limit="1" />' />
<txp:if_variable name="ac" value="">
There is nothing
<txp:else />
your tags here
</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: Plugin equivalent to if_article_custom?
Yiannis, thank you so much for your prompt reply — I really appreciate it.
Online
#4 2013-02-09 15:38:26
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Plugin equivalent to if_article_custom?
gaekwad wrote:
if 0 articles are returned then nothing happens and if 1 or more articles are returned, the contained command is run.
Er… that is exactly what happens if you just use the article_custom tag :)
Offline
Re: Plugin equivalent to if_article_custom?
Els wrote:
Er… that is exactly what happens if you just use the article_custom tag :)
Yeah, that’s what I thought, but I have weirdness with if_first_article
and if_last_article
in an article form: they’re evaluating as true, regardless as to whether there’s any output from article_custom
. Until I can figure out where my code is wrong, I’m going to offload if_first_article
and if_last_article
into a page rather than a form.
(Also, Els, you’re far better at this than I am, so I respectfully doff my cap for helping me out – thank you)
Last edited by gaekwad (2013-02-09 15:53:49)
Online
Re: Plugin equivalent to if_article_custom?
Hi Pete, can you post the current code(s) you are using?
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: Plugin equivalent to if_article_custom?
colak wrote:
Hi Pete, can you post the current code(s) you are using?
Sure. It’s messy, so you can be as rude as you want to be:
Example: Go Daddy coupons (heh, spam much?)
I have a snippet in the page template to spit out three sets of articles each with their own form:
Page
<txp:article_custom category='<txp:output_form form="coupon_table_sections_select" />' expired="0" form="coupon_table_expiry_none" limit="999" section="deals" sort="Expires asc" />
<txp:article_custom category='<txp:output_form form="coupon_table_sections_select" />' expired="0" form="coupon_table_expiry_expires" limit="999" section="deals" sort="Expires asc" />
<txp:article_custom category='<txp:output_form form="coupon_table_sections_select" />' expired="1" form="coupon_table_expiry_expired" limit="999" section="deals" sort="Expires asc" />
I’ll show you coupon_table_expiry_expires
as it’s one that’s causing a visible problem. The page selects articles which have not expired, and the form only does stuff with articles that have an expiry date set:
Form: coupon_table_expiry_expires
<txp:rah_replace from="
" to="">
<txp:hide>
*******************************************************
Site: petecooper.org
Name: coupon_table_expiry_expires
Type: form, article
Info:
*******************************************************
</txp:hide>
<txp:if_first_article>
<table class="table table-bordered table-condensed table-hover">
<thead>
<th>Working coupons with a 'use by' date</th>
</thead>
<tbody>
</txp:if_first_article>
<txp:if_expires>
<tr>
<td>
<txp:if_custom_field name="article-deal-description">
<p class="lead" style="margin-bottom:8px;margin-top:6px;">
<txp:if_custom_field name="article-deal-target-url">
<a href='<txp:custom_field name="article-deal-target-url" />'>
</txp:if_custom_field>
<txp:custom_field name="article-deal-description" escape="" />
<txp:if_custom_field name="article-deal-target-url">
</a>
</txp:if_custom_field>
<txp:if_article_image><txp:article_image height="1" width="1" /></txp:if_article_image>
</p>
<txp:if_custom_field name="article-deal-terms">
<h5 style="margin-top:15px;margin-bottom:0px;"><small><txp:custom_field name="article-deal-terms" /></small></h5>
</txp:if_custom_field>
</txp:if_custom_field>
</td>
<td style="text-align:center;">
<txp:if_custom_field name="article-deal-coupon">
<txp:if_custom_field name="article-deal-target-url">
<a href='<txp:custom_field name="article-deal-target-url" />'>
</txp:if_custom_field>
<h3 style="margin-bottom:2px;margin-top:3px;">
<txp:custom_field name="article-deal-coupon" />
</h3>
<txp:if_custom_field name="article-deal-target-url">
</a>
</txp:if_custom_field>
<txp:else />
<h3 class="muted" style="margin-bottom:2px;margin-top:0px;">—</h3>
</txp:if_custom_field>
<h5 style="margin-top:8px;margin-bottom:0px;">
<small>Expires <txp:expires format="%b %e '%g" /></small>
</h5>
</td>
<td style="text-align:center;">
<a href='<txp:if_custom_field name="article-deal-target-url"><txp:custom_field name="article-deal-target-url" /><txp:else /><txp:output_form form="article_merchant_target" /></txp:if_custom_field>' class="btn btn-success btn-large" type="button">GO!</a>
<h5 style="margin-top:7px;margin-bottom:0px;"><small><txp:permlink>Read more</txp:permlink>...</small></h5>
</td>
</tr>
</txp:if_expires>
<txp:if_last_article>
</tbody>
</table>
</txp:if_last_article></p>
<txp:hide>
*******************************************************
Site: petecooper.org
Name: coupon_table_expiry_expires
Type: form, article
Info:
*******************************************************
</txp:hide>
</txp:rah_replace>
Actually, posting it and explaining it here, I think I’ve pinned down the problem: the table
making stuff is outside the if_expires
container, so there will be something there, it just isn’t showing anything from the article.
Derp. I feel somewhat amateur. I’ll rejig and report back.
Online
Re: Plugin equivalent to if_article_custom?
Fixed. Tag nesting screw-up on my part. Oops.
I may have found some if_expired
weirdness, though. More later if I can reproduce it from scratch.
Nope. My code was faulty. Now, it’s fixed. Hurrah!
Last edited by gaekwad (2013-02-09 16:59:08)
Online
#9 2013-02-09 18:41:11
- els
- Moderator
- From: The Netherlands
- Registered: 2004-06-06
- Posts: 7,458
Re: Plugin equivalent to if_article_custom?
gaekwad wrote:
Actually, posting it and explaining it here, I think I’ve pinned down the problem
Yeah, this forum even functions without its members ;)
Offline