Textpattern CMS websites can use inbuilt tags that transform Textpattern-specific stuff into browser markup. In this article, the third in a series of five about Textpattern’s markup tags, I’ll explain how these two tags work:
- page_title
- page_url
Briefly, `page_title` is used to populate the `title` tag inside `head` and `page_url` returns part of the current URL, depending on the attribute.
Starting with `page_title` – frankly, it’s the more easily understood of the two tags for most people – it has a single, optional attribute that provides a method of separating parts of the title text. The output of `page_title` depends on what’s being viewed in the browser:
- Article list (including home page): the site name
- Articles by category: the site name : category title
- Search results pages: the site name : Search results: search term
- Single article page: the site name : article title
- Comments display: the site name : article title
Note the colon (`:`) separator between the site name and the second part of the title. This is a default setting that’s overridden by the `separator` attribute along with a substitute character. Like this:
<title> <txp:page_title separator="-" /> </title>
Also note that the character can be encoded, like this:
<title> <txp:page_title separator="·" /> </title>
Overall it’s a fairly straightforward, if a little inflexible, way of generating title text from the various sections of a Textpattern site. It’s not the most efficient method to create SEO-friendly `title` blocks, but if that sort of thing isn’t important to you then you need not spend any additional time thinking about it.
Next up: `page_url`. This one’s more powerful and complex than the last, so now is a good time to get a tasty snack. Go on, I’ll wait.
As a reminder, `page_url` extracts and outputs a component of the current URL, plus some Textpattern-specific stuff that has nothing to do with the URL. It has a single attribute, but it can do a lot of stuff. The `type` attribute specifies which component to retrieve:
- request_uri: current URL, including any query string (default setting)
- id: the current article’s numeric identification (on a single article page)
- s: the current URL’s section
- c: the current URL’s category
- q: the URL’s search query string
- pg: the current page number (in article list mode)
- month: the current page’s month (in time-based article lists)
- author: the current page’s author (in article lists filtered by author)
- status: the HTTP error response
- css: the current style sheet name (where the `css` tag is used)
- page: the current Textpattern page template name
This is much more low-level than squirting an auto-generated title between a pair of `title` tags in `head`. It’s very useful for development, troubleshooting and other situations where diagnostic information is required. I tend to use this tag to output URL-specific stuff in comments toward the end of the markup, a bit like this:
<!-- ****************************** --> <!-- url: <txp:page_url /> --> <!-- http: <txp:page_url type="status" /> --> <!-- section: <txp:page_url type="s" /> --> <!-- category: <txp:page_url type="c" /> --> <!-- ****************************** -->
That, combined with the inbuilt debugging mode offered by Textpattern, gives a useful insight into what I’m building and minimises tag spaghetti. Most of the time.
Next time: `css` and `feed_link`. I hope you’ll join me.
Looking for quality Textpattern Hosting? Look no further than Arvixe Web Hosting and use coupon TEXTPATTERN for 20% off your first invoice!