Textpattern Forum

You are not logged in. Register | Login | Help

#1 2012-07-18 08:41:08

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 559
Website

How to output article status in article_custom loop?

I would like to output something like <a title="Status: Hidden" ... > from an article_custom loop. I am using smd_tabber to show a tab with this list on the back end. Is it possible to print the status like this? Thanks.

Last edited by maruchan (2012-07-18 08:42:12)

Offline

#2 2012-07-18 10:11:49

Gocom
Developer
Registered: 2006-07-14
Posts: 4,465
Website

Re: How to output article status in article_custom loop?

While Textpattern itself doesn’t offer a dedicated tag for displaying the article’s status, custom_field and if_custom_field can get pretty much any field from the database, including article’s status.

Please bear in mind, that the behavior is something that is not by design and may change in the future. Likely not in the close one, but eventually a custom_field may not be able to retrieve values other than actual custom fields as supposed.

Anyways, the status field contains a numeric value ranging from 1 to 5, representing a status. When using a custom_field tag to return the status, you will get that raw number.

<txp:custom_field name="status" />

Would return something like 5. To get a human readable value out of it, you would have to substitute the number with a label. One of the easiest ways is to make a list of variables matching the numeric status, containing the human-readable label. Like so:

<txp:variable name="status_1" value='<txp:text item="draft" />' />
<txp:variable name="status_2" value='<txp:text item="hidden" />' />
<txp:variable name="status_3" value='<txp:text item="pending" />' />
<txp:variable name="status_4" value='<txp:text item="live" />' />
<txp:variable name="status_5" value='<txp:text item="sticky" />' />

Above deploys text tag to provide localized language strings. After that you can return a label by simply:

<txp:variable name='status_<txp:custom_field name="status" />' />

Avoids messy nesting of conditionals and anything like that.

Last edited by Gocom (2012-07-18 10:15:26)


Rah-plugins | What? I’m a little confused… again :-) <txp:is_god />

Offline

#3 2012-07-18 17:14:51

maruchan
Member
From: Ukiah, California
Registered: 2010-06-12
Posts: 559
Website

Re: How to output article status in article_custom loop?

Very nice, Jukka! Thank you for that solution.

Offline

Board footer

Powered by FluxBB