You are not logged in.
Do you know this “another article” that you want to check for a value in the custom field? or “another article” is just “any other article”?
Offline
th3lonius
I think I get what you’re doing but I’m not quite sure so I’ll hedge my bets here a bit. If it’s not quite right, the ideas in this example will probably get you moving in the right direction.
<txp:if_individual_article> <txp:if_custom_field name="link_thingy"><txp:variable name="link_to_find"><txp:custom_field name="link_thingy" /></txp:variable> <txp:variable name="got_one" value="0" /><txp:article_custom> <txp:smd_if field="txpvar:got_one, body" operator="eq, contains" value="0, txpvar:link_to_find"> <txp:hide> If we found a matching article, store its URL and bomb out </txp:hide> <txp:variable name="got_one" value='<txp:permlink />' /> </txp:smd_if> </txp:article_custom><txp:if_variable name="got_one" value="0"> <txp:custom_field name="link_thingy" /> <txp:else /> <a href="<txp:variable name="got_one" />"><txp:custom_field name="link_thingy" /></a> </txp:if_variable></txp:if_custom_field> </txp:if_individual_article>
It just grabs the custom field data you want to check from the current article and then uses an article_custom to iterate over every article until you find one that contains the custom field data in the body text. If it finds one, it stops looking (well, sort of!). Once it’s done with the article_custom it checks to see if it found a matching article and links to it. If not, it just displays the raw custom field value.
It’s untested and it’s not quick, but should work. I think. As your site grows you might be better off with smd_query.
Last edited by Bloke (2010-06-11 08:19:51)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern.
Txp Builders – finely-crafted code, design and Txp
Offline
maniqui wrote:
Do you know this “another article” that you want to check for a value in the custom field? or “another article” is just “any other article”?
Any other article. Stef’s example code does basically what I want. It checks the value in the custom field of this current individual article against the same field in all other articles.
My only problem, Stef, is that your code always returns a link so it seems to be checking the current article and, naturally, always finding the value its looking for. I think it would work perfectly if there is a good way to exclude checking the current article in the article custom call.
EDIT: I also had the thought that <txp:article_custom /> allows restricting to articles with a specified custom field name so I tried this:
<txp:article_custom director="txpvar:link_to_find">
with director being the name of the custom_field I’m checking but that didn’t work.
Last edited by th3lonius (2010-06-14 19:46:54)
Offline
th3lonius wrote:
a good way to exclude checking the current article in the article custom call.
Ah, didn’t think of that. Yeah, that could screw things up a bit.
Add this line to the declaration section along with the other txp:variables:
<txp:variable name="this_id" value='<txp:article_id />' />
and then use this smd_if line instead:
<txp:smd_if field="thisid, txpvar:got_one, body" operator="not, eq, contains" value="txpvar:this_id, 0, txpvar:link_to_find">
See if that works.
The smd plugin menagerie — for when you need one more gribble of power from Textpattern.
Txp Builders – finely-crafted code, design and Txp
Offline
Hi Stef,
I use smd_if for render a part of an article (which is populated with custom fields) but it doesn’t work.
I don’t know where is the bug.
Can you help me?
This is my code:
<txp:smd_if field="variante-1, variante-2, variante-3" operator="isused" logic="or"> <div id="bottom-details"> <h4>Varianti</h4> <div id="product-models"><txp:if_custom_field name="variante-1"> <div class="model"> <div class="model-code"> <p>Articolo <txp:custom_field name="variante-1" /></p> </div><!-- model-code --> <div class="model-desc"> <txp:upm_textile> <txp:custom_field name="descrizione-1" /> </txp:upm_textile> </div><!-- model-desc --> </div><!-- model --> </txp:if_custom_field><txp:if_custom_field name="variante-2"> <div class="model"> <div class="model-code"> <p>Articolo <txp:custom_field name="variante-2" /></p> </div><!-- model-code --> <div class="model-desc"> <txp:upm_textile> <txp:custom_field name="descrizione-2" /> </txp:upm_textile> </div><!-- model-desc --> </div><!-- model --> </txp:if_custom_field><txp:if_custom_field name="variante-3"> <div class="model"> <div class="model-code"> <p>Articolo <txp:custom_field name="variante-3" /></p> </div><!-- model-code --> <div class="model-desc"> <txp:upm_textile> <txp:custom_field name="descrizione-3" /> </txp:upm_textile> </div><!-- model-desc --> </div><!-- model --> </txp:if_custom_field></div><!-- product-models --> </div><!-- bottom-details --> </txp:smd_if>
Offline
Bloker: how do I use this to simply test for the existence of multiple values as opposed to a single value. I tried using this:
<txp:smd_if field="article_image" operator="contains" value="," >
to no avail…
any suggestions
Offline
hi Dale,
try <txp:smd_if field="article_image" operator="contains" value="," param_delim=";">.
That should work.
Offline
Hi,
Is it possible to compare the parent attribute to several values without repeating the attribute ?
Thanks for your answers
Nicolas
Offline