Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Add (st, nd, rd, th) to the end of the day date number
Add (st, nd, rd, th) to the end of the day date number
Would this be easily possible in the form of a plugin?
Sam Brown
sambrown.me | welovetxp.com
Offline
#2 2009-02-10 17:14:01
- Mary
- Sock Enthusiast
- Registered: 2004-06-27
- Posts: 6,236
Re: Add (st, nd, rd, th) to the end of the day date number
PHP supports this if you use the date() function, rather than strftime(). Txp uses strftime() for dates because then they can more easily be translated into languages other than English.
I’m found of the ordinal endings too, and so I use a custom date plugin that uses the other function. I think there was a published plugin (not mine) that did this, not sure if it still works or not.
Offline
Re: Add (st, nd, rd, th) to the end of the day date number
Hi Mary,
Thanks for the response, you’re right the old jad_oldposted plugin switches it back to date()
and it still works in 4.0.8.
<txp:jad_oldposted format="jS F Y" />
Displays 10th February 2009, exactly what I wanted.
Last edited by Sam (2009-02-10 17:40:28)
Sam Brown
sambrown.me | welovetxp.com
Offline
Re: Add (st, nd, rd, th) to the end of the day date number
Mary & Sam: THANK YOU!
Didn’t even needed to install jad_oldposted (I use it for a custom RSS-feed).
Textpattern projects: Maxvoltar, Made by Elephant, Twunch
Offline
Re: Add (st, nd, rd, th) to the end of the day date number
I’ve replicate this feature using the native <txp:variable> tag using this method…
In your article form (or wherever) put:
<txp:posted format="%e" /><txp:output_form form="ordinal_date" /> <txp:posted format="%B %Y" />
Then create an new misc form called ordinal_date as follows:
<txp:variable name="ordinal_date" value='<txp:posted format="%d" />' /><txp:if_variable name="ordinal_date" value="01">st<txp:else /><txp:if_variable name="ordinal_date" value="21">st<txp:else /><txp:if_variable name="ordinal_date" value="31">st<txp:else /><txp:if_variable name="ordinal_date" value="02">nd<txp:else /><txp:if_variable name="ordinal_date" value="22">nd<txp:else /><txp:if_variable name="ordinal_date" value="03">rd<txp:else /><txp:if_variable name="ordinal_date" value="23">rd<txp:else />th</txp:if_variable></txp:if_variable></txp:if_variable></txp:if_variable></txp:if_variable></txp:if_variable></txp:if_variable>
It ain’t pretty but it seems to work. If someone has a better or more concise way (without using a plugin) then please let me know.
Cheers,
Phil
Last edited by philwareham (2010-02-07 16:33:04)
Offline
Re: Add (st, nd, rd, th) to the end of the day date number
philwareham wrote:
It ain’t pretty but it seems to work.
Blimey! Convoluted, but hats off for managing it :-)
If someone has a better or more concise way
Not necessarily better — certainly quicker and uglier— but if you’d prefer one line of PHP instead, swap this for a <txp:posted />
tag:
<txp:php>
echo date("jS F Y", posted(array("format" => "%s")));
</txp:php>
Last edited by Bloke (2010-01-19 13:55:05)
The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.
Txp Builders – finely-crafted code, design and Txp
Offline
Re: Add (st, nd, rd, th) to the end of the day date number
Yep, that’s definitely more concise!
One thing I noticed Stef is that your method does not work seem in article lists (my rambling long-winded solution does though!).
Last edited by philwareham (2010-01-22 10:16:47)
Offline