My mta_article_id Textpattern Plug-in ¬
2006-12-12
I wrote a quick Textpattern plug-in today to spit back a “URL title” for an article ID instead of the numerical “ID” that <txp:article_id />
does and called it mta_article_id. Basically it’s intended to be a replacement of article_id
.
I needed it to be able to implement human-readable anchors for articles in sections (for example the autobiograpy and colophon parts of this site’s about section) that aren’t sections that one would really “browse” (so no permalinks), but are mainly fake static pages. In fact, I had intended to have this functionality before I posted my holiday wish list, but I couldn’t find a way to extract just the “URL title” that appears at the end of a Textpattern “Clean URL” permalink (atleast not without writing some custom PHP code).
I asked around on the Textpattern support forum and one kind soul pointed me to this post by one of the moderators describing exactly what I needed.
So, I downloaded the Textpattern plug-in template (see Anatomy of a Textpattern Plug-in for more details on Textpattern plug-in development), and merged the moderator’s code (basically a one-liner) with that of the implementation of the built-in article_id
in taghandlers.php (another one-liner), and—Voilà!—my first Textpattern plug-in.
Of course, I discovered that there’s now an <article_url_title />
tag as of Textpattern 4.0.5, but I’m still running 4.0.3. So, my plug-in was depricated before it was released, but the mention of article_url_title
only appeared on December 1st, right in the middle of when I was first working on getting “URL titles”, so I guess it’s excusable.
Regardless, you can download mta_article_id from the development section if you like.
Update: It turns out I had overestimated which version Textpattern is currently at. It’s currently only at version 4.0.4, so although version 4.0.5 will include the article_url_title
tag my plug-in is still needed in the meantime.