Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
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
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)
Offline
Re: How to output article status in article_custom loop?
Very nice, Jukka! Thank you for that solution.
Offline