WordPress Page Template Gotcha

In setting up the Localvore blog I needed to duplicate some of the custom pages that I made for this site. The categories page was the first. Lo and behold, when I went to select a custom template for the page I was writing, not only were there none, but the select box was also missing. If I reverted to the default WP template the box was there, but of course not my template.

A little sleuthing later, I discovered there’s a change to custom template handling in version 2.3. Ghu knows when it will get into the docs. (Hey, would you write documentation for free? Me neither. Let’s be thankful for what there is.)

Anyway, here’s the deal. If you want your custom template to be picked up and made available, you need to start it with:

<?php
/*
Template Name: name of your template
*/
?>

I’m not actually impressed. Parsing comments is always a kludge of desperation and in this case they had two better choices.

First, they could have done nothing at all, just showed all the page templates as they did in version 2.0. I found that perfectly acceptable.

Alternatively, PHP code is, or can be, well formed XML. <?php … ?> is what’s called a processing instruction(PI). The ‘<?’ is a signal that what’s inside is meant for some other processor than the xml parser. The ‘php’ identifies which processor. WordPress.org could just as well have added another another PI, say <?wpinfo … ?> into which they could stick this and any similar things they think up in the future.

Honestly, I like the first alternative. Don’t fix what’s not broken. But if you must, if it’s no more work, and it’s not, there’s no excuse for not following standards. There’s no way to know a priori that the comment they added is needed for function rather than just being nice to those who come after. In contrast, <?wpinfo would have told many, likely most, of their colleagues exactly what was going down.

This entry was posted in Tech Stuff. Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

You may use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
*

  • Recent Posts

  • Archives

  • Categories

  • Meta

  • Google site search

    Custom Search