Simple page titles

During the current update taking place on the TXP Tips site, I found that we needed to change quite a few things that had become stagnant. One of these items was the page title, which is easy to output using the internal txp:page_title tag.

More granular control

However, if you want a little more control over the output, one option is to use the following snippet, which essentially checks which page we are on in Textpattern and then produces a custom page title.

Dragon Babic previously wrote his own version of custom page titles which is very good. This snippet performs a further check that we need here on TXP Tips – whether or not we are on a search or author page.

The code

<txp:if_search>
	<txp:variable name="page-title" value='Search | TXP Tips' />
<txp:else />	
<txp:if_category>
	<txp:variable name="page-title" value='<txp:category title="1" /> | TXP Tips' />
<txp:else />
<txp:if_author>
	<txp:variable name="page-title" value='<txp:author title="1" /> | TXP Tips' />
<txp:else />
<txp:if_article_list>
	<txp:if_section name=",">
	<txp:variable name="page-title" value='Home | TXP Tips' />
	<txp:else />
	<txp:variable name="page-title" value='<txp:section title="1" /> | TXP Tips' />
	</txp:if_section>
<txp:else />
	<txp:variable name="page-title" value='<txp:title no_widow="0" /> | TXP Tips' />
</txp:if_article_list>
</txp:if_author>
</txp:if_category>	
</txp:if_search>

<title><txp:variable name="page-title" /></title>

Place the code in your default page or form for use before the closing </head> tag.

Most of the code should be self explanatory, although it is worth noting that the check for the default page <txp:if_section name=","> (the home page) is done within the <txp:if_article_list> conditional otherwise we always end up with Home | TXP Tips in the page title.

Edit: Please note that there is a plugin solution – arc_meta – that can be used instead of the above code which is based on internal TXP tags.

comments powered by Disqus