Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-08-24 13:24:08

clxm
New Member
Registered: 2009-08-17
Posts: 4

make an article title a link, only if it contains body content?

Hi there.

I’m making a site for my theater company. I have a section called “plays” which contains an article for every play. the company’s history spans more than 20 years, and we don’t have content yet for all the old ones, but I’d like to them to show up in the history, so I’ve made articles for those shows as placeholders . So my question. Is it possible to have a list of all the article titles in a section, while only linking the ones that actually have content in the body of the article?

I’ve looked through the forums and couldn’t really find anything like this, so I apologize if this has been covered before.
any ideas appreciated.

thanks,
clm

Offline

#2 2009-08-24 14:03:48

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: make an article title a link, only if it contains body content?

Untested idea follows:

In the article form you are using for this article list:

<txp:variable name="has_body" value='<txp:body />' />
<txp:if_variable name="has_body" value="">
<txp:title />
<txp:else />
<txp:permlink><txp:title /></txp:permlink>
</txp:if_variable>

Edit: Thanks Els; corrected the above (one too many <txp:else /> tags in your example).

re-edit: Thanks Matt, you’re quite right!

Last edited by jsoo (2009-08-24 18:20:38)


Code is topiary

Offline

#3 2009-08-24 16:23:46

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

Re: make an article title a link, only if it contains body content?

jsoo wrote:

<txp:if_variable name="has_body">

Almost, but not quite :) The tag <txp:variable name="has_body" value='<txp:body />' /> creates the variable, no matter if the value is empty or not. What you are doing is testing if the variable exists, and with this code it will always exist. Instead you’ll need to test if it’s value is empty or not:

<txp:variable name="has_body" value='<txp:body />' />
<txp:if_variable name="has_body" value="">
<txp:title />
<txp:else />
<txp:permlink><txp:title /></txp:permlink>
</txp:if_variable>

Of course I only know this because I made the same mistake when I was trying to figure out the new variable tags… :)

(edit: I shouldn’t post code when I have only 10 seconds to do so… thanks MattD.)

Last edited by els (2009-08-24 20:58:26)

Offline

#4 2009-08-24 17:42:17

MattD
Plugin Author
From: Monterey, California
Registered: 2008-03-21
Posts: 1,254
Website

Re: make an article title a link, only if it contains body content?

To clarify I think you meant the code to look like this

<txp:variable name="has_body" value='<txp:body />' />
<txp:if_variable name="has_body" value="">
<!-- no content -->
<txp:title />
<txp:else />
<!-- content -->
<txp:permlink><txp:title /></txp:permlink>
</txp:if_variable>

My Plugins

Piwik Dashboard, Google Analytics Dashboard, Minibar, Article Image Colorpicker, Admin Datepicker, Admin Google Map, Admin Colorpicker

Offline

#5 2009-08-24 19:27:59

clxm
New Member
Registered: 2009-08-17
Posts: 4

Re: make an article title a link, only if it contains body content?

That worked! Thank you all. And I think, maybe, I am beginning to understand this txp:variable tag a bit, even.

Offline

#6 2009-08-24 20:59:10

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

Re: make an article title a link, only if it contains body content?

MattD wrote:

To clarify I think you meant the code to look like this

Thanks Matt, again… (edited my post above).

Offline

Board footer

Powered by FluxBB