Nice custom page titles for Textpattern sites

It’s no secret that SuperawesømeTextpattern. We love working with the CMS, especially because of the special way templating is implemented that’s super–easy for a designer to understand.

One thing that’s kind of difficult to achieve, is the complete customization of the page titles. For some reason, I like a site to be completely customized, and I am really happy Textpattern offers this level of fine–grained control over content.

Customized Page Titles in Textpattern

I usually have a couple of rules when it comes to page titles:

  • I want a special title on the home page,
  • I want a special title on the section lander,
  • I want a special title on the category lander within a section (for articles that are within categories, and sections),
  • I want a special title on the individual article page.

In order to achieve this, use this Textpattern template code:

<title>

  <txp:hide>check to see if we're on the home page</txp:hide>

  <txp:if_section name="">

    <txp:hide>we are, display the site's name and slogan</txp:hide>

    <txp:site_name /> — <txp:site_slogan />

  <txp:else />

    <txp:hide>we're not on the home page, check to see if we're in an article listing</txp:hide>

    <txp:if_article_list>

      <txp:hide>check to see if we are in a category listing</txp:hide>

      <txp:if_category>

        <txp:hide>we're in a category listing, display the category and section titles</txp:hide>

        <txp:category title="1" /> — <txp:section title="1" />

        <txp:else />

        <txp:hide>we're in a regular section listing, display section title</txp:hide>

        <txp:section title="1" />

      </txp:if_category>

    </txp:if_article_list>

    <txp:hide>check to see if we're on an individual article page</txp:hide>

    <txp:if_individual_article>

      <txp:hide>we are on an individual article page</txp:hide>

      <txp:title />

      <txp:hide>check to see if the article is in a category</txp:hide>

      <txp:if_article_category>

        <txp:hide>it is, display category2 title (for you this may be category1)</txp:hide>

        — <txp:category2 title="1" />

      </txp:if_article_category>

      <txp:hide>display article's section title</txp:hide>

      — <txp:section title="1" />

    </txp:if_individual_article>

    <txp:hide>always display the site's name</txp:hide>

    | <txp:site_name />

  </txp:if_section>

</title>

See the GitHub gist or the blog post for more!

comments powered by Disqus