Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
I'm not good with if and else strings ... help!
On this homepage I only want something rendered if there is a live article with a specific category. Although it’s a simple one I’m not good with if and else strings … that’s for sure.
<txp:if_category name="important"><div class="important">
<txp:article_custom section="artikelen" category="important" limit="2" form="single_nolink_sidebar" sort="rand()" />
</div>
<txp:else />
</txp:if_category>
Why doesn’t this work?
Offline
Re: I'm not good with if and else strings ... help!
Joop, if_category is true only if you append ?c=important
to the url. I think
<txp:article_custom section="artikelen" category="important" limit="2" form="single_nolink_sidebar" sort="rand()" wraptag="div" class="important" />
should suffice.
Offline
Re: I'm not good with if and else strings ... help!
The code doesn’t try to do what you are after. The if_category conditional checks if you are on a category page, opposed to querying content as described in the docs.
Instead you could use the article_custom tag’s wraptag
and class
attributes to add a wrapper to the list, if_first_article and if_last_article within the list itself to add markup to the last and first item, or variable and if_variable to check whether the tag returns anything. E.g.
<txp:article_custom wraptag="div" class="foobar" />
Offline
#4 2013-06-27 14:39:54
- uli
- Moderator
- From: Cologne
- Registered: 2006-08-15
- Posts: 4,315
Re: I'm not good with if and else strings ... help!
Here’s the rest of my post, as Jukka and Oleg answered the most part.
If there is an article at all in category your-category then show some from other ones:
<txp:variable name="catchecker" value='<txp:article_custom category="YOUR-CATEGORY">•</txp:article_custom>' />
<txp:if_variable name="catchecker" value="">
<txp:else />
<txp:article_custom section="artikelen" category="important" limit="2" form="single_nolink_sidebar" sort="rand()" />
</txp:if_variable>
Last edited by uli (2013-06-27 15:07:36)
In bad weather I never leave home without wet_plugout, smd_where_used and adi_form_links
Offline
Re: I'm not good with if and else strings ... help!
I’m ashamed … a wraptag and a classname is sufficent … :$ … and only if I change the article status or delete the article(s) off course. Thanks all!
Last edited by RedFox (2013-06-27 14:52:50)
Offline