Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2017-01-09 16:17:53

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 805
Website

How to use txp:if_keywords ... !?

This doesn’t work if I give an article the keyword ‘sold’:

<article class='<txp:if_keywords keywords="sold">sold</txp:if_keywords>' role="article" itemscope itemtype="http://schema.org/Article">
<div itemprop="articleBody">
</article>

It outputs:

<article class role="article" itemscope="" itemtype="http://schema.org/Article">

What to do to get that ‘special’ classname?

Offline

#2 2017-01-09 17:09:00

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,007
Website GitHub Mastodon Twitter

Re: How to use txp:if_keywords ... !?

Hi, the way I understand it is if he keyword is sold, then you would like to state that, if not, you do not want to show anything there right?

If that is the case try the untested code below.

<article class="<txp:if_custom_field name="keywords" value="sold">sold<txp:else /></txp:if_custom_field>"  role="article" itemscope itemtype="http://schema.org/Article">
<div itemprop="articleBody">
</div> <txp:hide>--- The div needs closing</txp:hide>
</article>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2017-01-09 17:22:57

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: How to use txp:if_keywords ... !?

It would be better to write the snippet…

<txp:if_keywords keywords="sold">class="sold" </txp:if_keywords>

… and the code must be in the context of an individual article.

Offline

#4 2017-01-09 18:16:04

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 805
Website

Re: How to use txp:if_keywords ... !?

Stupid me … but it’s solved (for now) … thanks to you both … :))

<article class='<txp:custom_field name="sold" />' role="article" itemscope itemtype="http://schema.org/Article">
<div itemprop="articleBody">...</div>
</article>

Last edited by RedFox (2017-01-09 18:16:34)

Offline

#5 2017-01-09 18:29:52

GugUser
Member
From: Quito (Ecuador)
Registered: 2007-12-16
Posts: 1,473

Re: How to use txp:if_keywords ... !?

I recommend you to use my snippet, otherwise you have an empty class if the keyword don’t match. Or, if you use a custom field, then it should be like:

<article<txp:if_custom_field name="sold"> class="<txp:custom_field name="sold" />"</txp:if_custom_field> role="article" itemscope itemtype="http://schema.org/Article">

Offline

#6 2017-01-10 09:50:55

RedFox
Member
From: Netherlands
Registered: 2005-03-25
Posts: 805
Website

Re: How to use txp:if_keywords ... !?

I’ve changed the snippet into <txp:if_custom_field name="sold?">class="sold"</txp:if_custom_field> … thanks!

Last edited by RedFox (2017-01-10 10:00:04)

Offline

Board footer

Powered by FluxBB