Uncategorized

Textpattern: Conditional Page Titles

You may have seen that some talented web builders serve up customized tags, so the very top of the browser shows a different title, depending on the current page/section.

Thinking that was pretty cool, I looked at the default title line:
<txp :page_title />
This serves the same title of your site to every page in your site.

Nathan described the wonders of the “section” tab, so I tried editing it this way:
<txp :page_title /> - <txp :s />
which does successfully customize the title depending on the current section. And I think that if you use in the of your page, TxP is smart enough not to output “default” on the home page.

However, since goes in the , the code above produced this on the home page:

Michael Montgomery.net – default

Definitely not cool.

So, what about conditional tags? has the answer:


<txp :page_title />

<txp :page_title /> || <txp :s />

The first line tests whether you’re currently on the home page, because name=”” refers to the default section. As a result, this is the home page’s title:

Michael Montgomery.net

and this is the “About” page’s title:

Michael Montgomery.net || About

Done!

Standard