TapCode Comments

Putting comments in code is a well established, if not rigidly employed method of documenting what the thing does. At best it tells future maintainers how it works and at worst it reminds you when you come back to it later. It doesn’t do anything else. With WordPress it does!

I wanted to make one page in a blog type application look different. The WordPress documentation says that first it looks for a template called pagename.php

Any custom Page Template selected for the page – If the page slug were about, WordPress would look for about.php

failing that then one called page.php and finally index.php working down the hierarchy until it finds one that exists. Now you would think that “pagename” was the name of the page—wrong!

After rootling through the forums I discovered that you have to select a custom “Page Template” on the write/manage page admin panel, THEN it directs it to use the right one.

Looking at the panel—no sign of a “Page Template” menu as promised. Further deep hunting on the forum and even resorting to Google I discover that you have to declare your custom templates—by adding a comment to the beginning in the form

<?php
/*
Template Name: templatename
*/
?>

Now the menu appears and you can chose between “Default Template” or the one you have declared “templatename” That is what I meant. These are not comments, even if they look like comments because the theme integration code is reading and interpreting them. They are effectively executed. I wonder if that is true for any others?

Comments are closed.

^ Top