Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-04-17 07:08:34

reedco
New Member
Registered: 2011-04-17
Posts: 2

Custom Fields Issue

I am working on a portfolio website for a writer. Writing samples are being stored as articles, which works splendidly. The writer has some writing samples where she wants to link to the work online. For this, I’m using a custom field to store the URL. This is working nicely, as I can dump the contents of the custom field through an article form into an anchor tag. It looks like:

<a href="<txp:custom_field name="URL" />">Go to Website</a>

The problem is that some of the writing samples do not exist online and do not have URLs. Consequently, the custom field is empty. For these articles, I want TextPattern to output no anchor. This is where I’m having trouble.

I’m aware of the <txp:custom_field /> “default.” Unfortunately, the <txp…> tag is wrapped in the anchor.

What I need is an IF conditional statement that examines the contents of the custom field. I’ve tried using PHP but it appears that TextPattern tags don’t play nicely in this environment. So, I’d like to use something like this to grab the field:

@<txp:php>

$q=“SELECT custom_1 FROM textpattern WHERE ID=\”*$id*\”“; // Get the ‘URL’ field

$result=mysql_query($q); // Assuming the DB connection is set up

$url=mysql_fetch_assoc($result); // Resource to variable

if(!empty($url[‘custom_1’])) echo “<a href=\”$url\”>Go to Website</a>”; // Anchor output
</txp:php>@

I assume TextPattern uses a loop to iterate the article form over each applicable article. I need to know what variable it uses for the article ID ($id in the above) and if I can use it.

Any help or insight would be greatly appreciated.

Last edited by reedco (2011-04-17 07:11:13)

Offline

#2 2011-04-17 07:58:46

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

Re: Custom Fields Issue

Did you try?

<txp:if_custom_field name="URL"><a href="<txp:custom_field name="URL" />">Go to Website</a></txp:if_custom_field">


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 2011-04-17 08:04:22

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

Re: Custom Fields Issue

reedco wrote:

What I need is an IF conditional statement that examines the contents of the custom field.

Conditional tags :)

Offline

#4 2011-04-17 08:10:03

reedco
New Member
Registered: 2011-04-17
Posts: 2

Re: Custom Fields Issue

Well, that’s handy.

Thanks for your help!

Offline

Board footer

Powered by FluxBB