Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-05-11 16:07:10

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 1,000
Website

[SOLVED] Output markup block only if custom field content is different

Hi!

I want to output a list of articles sorted by a custom field. Each article has different content in the title and body fields, but some of them share the same input in a certain custom field. For articles that share the same data in the specified custom field, I want to output only the first article header, which includes the title and other custom field data.

Here’s an example:

 <!-- !conditional: Show this only if the content of custom_X is different
.............................................. -->
<header>
<h2 id="topic-<txp:article_url_title/>"><txp:title/></h2>
<txp:if_custom_field name="custom_X"><dl>
<dt>##custom_X_label##</dt>
<dd><a href="<txp:custom_field name="custom_Y"/>"><txp:custom_field name="custom_X"/></a></dd>
</dl></txp:if_custom_field>
</header>
<!-- End of !conditional -->

<!-- !perennial: Show this for every article, even if custom_X is the same.
.............................................. -->
<txp:body/>
<!-- End of !perennial -->

I’m sure this can be achieved with some combination of if_different and if_variable, but I can’t figure it out. I’d be grateful for any insight!

Last edited by johnstephens (2011-05-12 17:04:07)

Offline

#2 2011-05-11 19:01:41

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: [SOLVED] Output markup block only if custom field content is different

 <!-- !conditional: Show this only if the content of custom_X is different
.............................................. -->

<txp:variable name="cfX" value='<txp:if_different><txp:custom_field name="custom_X" /></txp:if_different>' />

<txp:if_variable name="cfX" value="">
<txp:else />

<header>
<h2 id="topic-<txp:article_url_title/>"><txp:title/></h2>
<txp:if_custom_field name="custom_X"><dl>
<dt>##custom_X_label##</dt>
<dd><a href="<txp:custom_field name="custom_Y"/>"><txp:custom_field name="custom_X"/></a></dd>
</dl></txp:if_custom_field>
</header>
<!-- End of !conditional -->

</txp:if_variable>

<!-- !perennial: Show this for every article, even if custom_X is the same.
.............................................. -->
<txp:body/>
<!-- End of !perennial -->

You need to sort by custom_X of course.

Offline

#3 2011-05-12 17:04:41

johnstephens
Plugin Author
From: Woodbridge, VA
Registered: 2008-06-01
Posts: 1,000
Website

Re: [SOLVED] Output markup block only if custom field content is different

Thank you, Els! This is exactly what I needed.

Offline

Board footer

Powered by FluxBB