Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-05-08 20:13:12

hicks
Member
From: Portland, OR, USA (ex-UK)
Registered: 2009-05-08
Posts: 106
Website

article_id formatting

Hello,

I’d like to show my article ID# on my blog in a three-figure format, e.g. 001, 002, 076. Is there a way?
The first idea that came to mind was using an if/else on articles with IDs under 10 having two zeros ahead of the <txp:article_id /> in the form, or articles 10-99 having one zero, if that’s doable with some txp code I can’t find elsewhere.
Help?

Thanks!

Offline

#2 2009-05-08 20:18:33

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: article_id formatting

<txp:php>
printf("%03d", article_id());
</txp:php>

Offline

#3 2009-05-08 21:39:51

hicks
Member
From: Portland, OR, USA (ex-UK)
Registered: 2009-05-08
Posts: 106
Website

Re: article_id formatting

Thanks JM! I put that in the form, which worked a treat. Is there somewhere else I can put it instead to make it site-universal? I somewhat new-ish to TextPattern.

Offline

#4 2009-05-09 01:46:30

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: article_id formatting

You could create an article form called “post_id” containing the code I posted, and then in your default form (or whatever you’re using), use the following:

<h2>Post ID: <txp:output_form form="post_id"/></h2>

Offline

#5 2009-05-09 01:52:32

hicks
Member
From: Portland, OR, USA (ex-UK)
Registered: 2009-05-08
Posts: 106
Website

Re: article_id formatting

Thank you.

Offline

Board footer

Powered by FluxBB