Presentation and Templates category listing. ­ Textpattern CMS

FAQ: Presentation and Templates

Can I use multiple CSS stylesheets?


How do I include several CSS stylesheets on a page?
How do I link to a style by name?
How do I use a CSS stylesheet for printing?


The standard CSS stylesheet link in the default template looks like this:

<link rel="stylesheet" href="<txp:css />" type="text/css" media="screen" />

The <txp:css /> part tells Textpattern to use the stylesheet associated with the current section (see presentation > sections).

You can link to additional stylesheets on the same page by referring to them by name. Create another style (under presentation > styles) and add an extra line to your template like this:

<link rel="stylesheet" href="<txp:css name="my_style_name" />" type="text/css" media="screen" />

The name parameter specifies the name of the stylesheet. Read more at Textpattern Tag Reference: css.

To add a print-only stylesheet, create one named print and add this to your page template:

<link rel="stylesheet" href="<txp:css name="print" />" type="text/css" media="print" />

How do I make links open in a new window?


How do I add a target attribute to links?
How do I add a rel attribute to links?


You can use the PR Block plugin to add rel, target and similar attributes to links.

Here’s a simple method of making all links contained within an article body open in a new window:

<txp:zem_prblock target="_blank">
<txp:body />

The plugin will modify any <a href=...> tags it encloses, so you can wrap the zem_prblock tag around a txp:linklist tag, for example.

For a standards-compliant solution, use the PR Block plugin to add a rel="external" attribute to links:

<txp:zem_prblock rel="external>

Then use javascript to make all rel="external" links open in a new window.

Can I use tags within tags?


Can I use one tag as the attribute to another tag?


Textpattern supports nested tags — that is, enclosing one tag within another. For example, from the default article form:

<txp:permlink><txp:title /></txp:permlink>

It is also possible to use one tag as an attribute for another by embracing the attribute with single quotes:

<txp:article_custom section='<txp:section />' />

Single quotes serve as an indicator to Textpattern that it should feed the result of the embedded tag into the outer tag’s attribute, as opposed to the literal text which is used by embracing an attribute value with the usual double quotes.

See the weblog post on Textpattern’s tag parser for an in-depth explanation.

How do I show a list of related articles?


How do I display a list of articles related to the current one?


Use the txp:related_articles tag in your page template or article form.

<txp:related_articles /> will list articles in the same category as the currently displayed article.

How do I make an archive page?


How do I make an archive of articles grouped by month?
How do I show a list of all articles?


(This technique requires Textpattern 4.0.2+)

Here’s a step-by-step method for creating a page that lists all articles with headings for each month (or year):

1. Create a new article form (presentation > forms). Call it monthly_article:

<!-- show the year -->
<h2><txp:posted format="%Y" /></h2>
<!-- show the month -->
<h3><txp:posted format="%B" /></h3>
<!-- article title and link -->
<txp:permlink><txp:title /></txp:permlink>
<br />

2. Copy an existing page template (such as default) to a new one named archive_list.

3. Edit the archive_list template. In the main content block, replace the <txp:article /> tag with this:

<txp:article_custom limit=99999 form="monthly_article" />

4. Create a section named archive, list, or similar. The section page ( or will be used to display the list of articles. Select archive_list as the page template (“Uses page:”).


The monthly_article form above will display the year and month separately. You can combine them together like this:

<txp:if_different><h3><txp:posted format="%B %Y" /></h3></txp:if_different>

The format string can include any of the format specifiers supported by PHP’s strftime function. (Beware, Windows doesn’t support all of those). <txp:if_different> only displays its enclosed content when that content changes.

To include an excerpt, timestamp, category name or other information with each article link, simply use the appropriate article form tags in the monthly_article form.

To display the articles in an unordered list, use a li tag in the monthly_article form:

<txp:permlink><txp:title /></txp:title>

..and, in the archive_list page template, wrap the article_custom tag in a ul:

<ul><txp:article_custom limit=99999 form="monthly_article" /></ul>

To display only articles from a specific section or category, change the article_custom tag:

<txp:article_custom limit=99999 form="monthly_article" section="products" />


<txp:article_custom limit=99999 form="monthly_article" category="weather" />

To group articles by something other than date, such as section, create a form named section_article:

<!-- show the section -->
<h2><txp:section title=1 /></h2>
<!-- article title and link -->
<txp:permlink><txp:title /></txp:title>
<br />

And change the article_custom tag to sort by section:

<txp:article_custom limit=99999 form="section_article" sortby="section" />

Page output is unstyled


My page content and layout displays without any CSS styling


This is most commonly caused by an incorrect txpath setting in config.php.

View the HTML source of the page, and look for the <link rel="stylesheet" href="..." type="text/css" /> tag.

If the href link is incorrect—it should point to css.php?s=mysection or textpattern/css.php?s=mysection—you’ll need to edit config.php and fix the txpath setting. Check for an extra slash character, or repeated subdirectory name.

If the link appears correct, try pasting the CSS url directly into the address bar in your browser, and checking the output. Some possible diagnoses:

404 not found – your textpattern/css.php file is missing.

PHP error – if there’s a PHP error at the beginning of the CSS output, check the FAQ for more information.

HTML – if the CSS URL displays a HTML page instead of CSS code, you most likely have a missing css.php file, and/or an overzealous .htaccess RewriteRule. Try disabling .htaccess and switching to “messy” URL mode.

Blank page – switch the Production Status to Testing and reload.

If you just updated and expect to see your site here.. – if the CSS output includes this message, you haven’t updated the css.php file correctly when upgrading.

If you’re seeing some CSS styling, but not the style you’d expect, make sure you’ve applied the correct stylesheet to your section (textpattern > presentation > sections, “Uses style:”).

If you’ve manually created a <link rel="stylesheet" ... /> tag, rather than using the <txp:css /> tag in your template, make sure you’ve used the correct URL.

How do I search in the current section only

You can easily display search results for a given section only. All you need to do is to add a couple of custom attributes to the <txp:search_input /> and <txp:article /> tags on the template page for that section.

  1. First, you need to point the search input to the current section page, by adding to the <txp:search_input /> the attribute section with the current section name as the value.
  2. Then, in order to display the search results only for that section, you have to add searchall=”0” as attribute for the <txp:article /> tag on that page.

Where can I get the default templates?


How do I restore the default templates, forms, and styles that came with Textpattern?
I messed up my default template/form, how do I fix it?


The default templates, forms and styles that come with Textpattern are all listed in Textbook:

You can save or restore them into your Textpattern site by pasting the contents of each into the edit interface – presentation > templates, presentation > forms, or presentation > styles.

Comment display confusion


Why does the comment for show up twice?
How do I change the comment display markup?
What are all these comment forms for?


Earlier versions of Textpattern were inflexible in the way comments were displayed. The list of comments, and comment input form, were always appended to the end of an article on an individual article page. This made it impossible to shift the comments to a different part of the layout (like a separate column), or display them on list pages.

Since RC5, there are some new comment tags that provide greater flexibility.

The default behaviour is to mimic older versions, by automatically appending comments and the comment input form to articles. You can disable this behaviour by turning off the Automatically append comments to articles? option on textpattern > admin > prefs.

If you disable that setting, you’ll need to manually include the necessary comment tags in your article form, or comments won’t be displayed at all. (Conversely, if you use these comments tags without disabling the Automatically append comments to articles? setting, you’ll see comments displayed twice).

The important tags are:

  • txp:comments – displays the list of comments. By default, this uses the form named “comments” to display each comment.
  • txp:comments_form – displays the comment input form. By default, the input form markup is stored in the form named “comment_form”.
  • txp:if_comments_allowed – checks if comments are permitted for the current article

The default forms are:

  • comments – this is used by the <txp:comments /> tag to display each comment in the list
  • comment_form – this is the comment input form, as displayed by <txp:comments_form />
  • comments_display – this contains the code to display the comment input form, preview, and list of comments for an article.

You’ll find a minimal set of comment tags in the default comments_display form.

If Automatically append comments to articles? is turned on, this form is used automatically each time an article is displayed.

If you’ve turned off Automatically append comments to articles?, append this code (or something like it) to your article form as a starting point.

What does article_custom do?


What’s the difference between <txp:article /> and <txp:article_custom />?
I used <txp:article_custom />, and now something isn’t working!


The <txp:article /> tag is context sensitive. The article(s) it displays depends on the URL of the current page. The results will change if the URL includes a section, for example, or a category, or a search query, an article ID, or a page number parameter. It’s normally used to display the main content of a page.

The <txp:article_custom /> tag ignores the page URL. The article(s) it displays depends only on the tag attributes. The results won’t change on a search result page, when navigating by category, section or article, or when paging. It’s typically used to display a list of articles in a sidebar.

See also Why aren’t the right articles showing up on my page?

How do I keep a post at the top of the page?


How do I create an article that isn’t included in the regular article list?
How do I create an article that’s only displayed on the front page, and nowhere else?


This is what Sticky articles are for.

The Sticky status means an article has been published, but is not included in the regular list of articles. It’s displayed only when requested with the status="sticky" attribute. For example:

<txp:article status="sticky" limit=1 />
<txp:article limit=10 />

..will display the most recent Sticky article, followed by the 10 most recent Live articles. On a section page, both tags will select articles from the current section only. On the front page, these tags will select articles from sections that have On front page? set to Yes.

To display a specific Sticky article, rather than the most recent, use the following tag:

<txp:article_custom status="sticky" id="123" />

..where 123 is the ID number of the article you want to show. You can use this to show a sticky article in a section other than the one it belongs to, or to pin a specific article to the front page of your site. The article_custom tag ignores the URL, so the selected section has no effect.

A commonly requested variation is to display an introduction on a section page (or the front page), with headlines or manually crafted links to individual article pages. For that, you can combine Sticky articles with the conditional tag method outlined in this faq:

<!-- section page: display the sticky article -->
<txp:article status="sticky" limit=1 />
<txp:else />
<!-- article page: display the live article -->
<txp:article limit=1 />

How do I change the article markup?


How do I get rid of <p> or <br> tags in article bodies?
How do I get more control over HTML markup in article bodies?
Why are my excerpts enclosed in <p> tags?
How do I turn off Textile?


By default, Textpattern articles are written in Textile, the Humane Web Text Generator. Some quick examples of Textile in action:

*bold* becomes bold
_emphasis_ becomes emphasis
"link": becomes link

You can read more about Textile here, and try it out for yourself.

As well as explicit markup such as the examples above, Textile automatically wraps blocks of text with <p>...</p> tags, and turns line breaks into <br /> tags.

If this is inconvenient, you can turn Textile off individually for a single article with the Use Textile setting under Advanced Options, just to the left of the main article text on the content > write page. There are separate settings for the body and excerpt.

To turn off Textile by default, look for the Use Textile setting under admin > preferences.

Both options require that you resave your article before they have any effect.

If you just want to disable Textile for part of an article, you can use several methods:

1. A space at the beginning of a line will turn off <p>...</p> tags for that line

2. To disable Textile for a few words, use ==...==

3. To disable Textile for a larger block, use <notextile>...</notextile>

If you’re writing an article body or excerpt that consists mainly of hard-coded HTML or Textpattern tags, or where you need exact control over the markup, your best bet is to turn off Textile for that article, and hand-code the markup yourself.

How do I skip the comment preview?


How do I get rid of the comment preview, and make it a one-step submit?


You don’t. The preview step is an important part of Textpattern’s anti-spam mechanism. And trust me, you need that. The only reports we’ve received of automated comment spam against Textpattern is on sites where the preview mechanism has been disabled.

There are some instructions floating around that describe ways of disabling it. Usually these are for older versions of Textpattern, and often the result is that comments stop working, or something else fails.

How do I change the number of articles displayed?


How do I change the number of articles displayed in a list?
How do I tell Textpattern to display only 1 (or 10, or 100) articles per page?


Edit your page template, and change the <txp:article /> tag to include a limit attribute, like this:

<txp:article limit=1 />

or this:

<txp:article limit=10 />

If no limit is specified, the default is 5.

To link to the next and previous pages from a list page (i.e. on your front page, or a section page), use the txp:older and txp:newer tags.

To link to the next and previous article from an article page, use the txp:link_to_next and txp:link_to_prev tags.

You can do this with one chunk of code in your page template, as used in Textpattern’s default template:

<txp:link_to_prev><txp:prev_title /></txp:link_to_prev>
<txp:link_to_next><txp:next_title /></txp:link_to_next>

How do I embed Textpattern in another page?


How do I embed Textpattern in another page or script?
I tried include()ing publish.php and it didn’t work!


Textpattern is designed as a stand-alone application. Trying to embed it in another page or script doesn’t work well, for various reasons. (In particular, Textpattern uses output buffering, If-Modified-Since caching, and sends HTTP headers, all of which usually interfere with wrapper scripts)

Usually that turns out not to be nessary though. Try doing things the other way around: embed your content or script in Textpattern, using page templates, forms and < txp:php> tags. That way you’ll have a consistent interface for editing all of your pages.

Which articles go on the front page?


How do I control which articles are shown on the front page?
How to I make the front page show articles from particular sections?
How do I stop articles from some sections from showing up on the front page?


Each section has a setting that controls whether or not its articles will be shown on the front page by default.

Go to textpattern > presentation > sections, and select On front page? appropriately for each section.

How do I reuse chunks of HTML?

  • Is there a way to reuse chunks of HTML like headers and footers?
  • How do I include small bits of static content in a page


Create a new form containing the chunk of HTML. Give it a name (say, “myform”). Set the type to Misc.

Now, anytime you want to reuse that form, use <txp:output_form form="myform" /> to display it.

How do I manage static pages?


How do I create and manage static (non-blog) pages?
How do I create an “about” page, “contact” page, etc?


The short answer: create a section, use an article form that doesn’t include posted dates or permlinks, and post a single article in that section.

The long answer: when you view a URL like, Textpattern will display the section named contact, using the page template selected for the contact section. (This assumes your Textpattern front page is

The usual way to manage content on a “static” (single, stand-alone) page like this is as follows:

1. Create a new article form named static_article, with the following contents:

<h3><txp:title /></h3>
<p><i><txp:excerpt /></i></p>
<txp:body />

This will be used to display the article contents on your static page. You can change the markup later if you want.

2. Copy your default page template to a new template named static_page. Find the <txp:article /> tag in the static_page template, and change it to look like this:

<txp:article limit="1" form="static_article" status="sticky" />

This template will be used to display your static page.

3. Create a new section named contact (or whatever you want your page to be called). Go to presentation > sections and set Uses page to static_page for your new section.

4. Post a new article in the contact section, with the article status set to Sticky instead of Live.

The most recent Sticky article will be displayed as the page contents when you view the URL

To create additional static pages, you can skip steps 1 and 2, and reuse the same static_page template.

For the best way to create links to your static pages, see How do I create navigation links?

For a more detailed description, read Managing Static Pages With Textpattern

How do I show only an excerpt in article lists?


How do I show excerpts in article lists, and the full text on each article page?
How do I show a “read more” link for each article?
How do I use a different layout for article lists and invidividual article pages?


Textpattern provides two main text fields per article: the Body and the Excerpt. The Body is the main article content. The Excerpt is normally used for a summary, introductory paragraph, abstract or similar.

To implement a “Read More” link, we’ll display the Excerpt on list pages (such as the front page and section pages), and the Body on the individual article (‘permlink’) pages. There are two ways to do this: one by using separate forms for the list and article pages; and another by using a single article form with a <txp:if_article_list> tag.

Method 1:

Use two article forms: one that shows only the excerpt, and one that shows the full article. Your main article form (typically ‘default’) would normally contain a <txp:body /> tag, which displays the complete article.

Create a new article form named “excerpt”, containing something like this:

<txp:excerpt />
<txp:permlink>read more</txp:permlink>

Your default form normally contains something like this (edited for brevity):

<h3><txp:permlink><txp:title /></txp:permlink></h3>
<txp:excerpt />
<txp:body />

In your page template, use <txp:article form="default" listform="excerpt" />.

This means that the default form will be used for full article pages, and the excerpt form will be used for list pages. To change the appearance of either page (e.g. to remove the excerpt from the full article page), edit the appropriate form.

(For more information the article tag and forms, see ‘How do I select which form is used to display articles?’)

Method 2:

Use an article form, containing something like this:

<! -- list page: display the short version -- >
<txp:excerpt />
<txp:permlink>read more</txp:permlink>
<txp:else />
<! -- article page: display the complete article -- >
<txp:body />

If you want to include the excerpt as well as the body on the article page, just add a <txp:excerpt /> tag above <txp:body />.

Conditional Layout

With either of the above methods, you can use the <txp:if_excerpt> tag inside the article form to lay out articles with and without excerpts differently. For example, to apply separate CSS classes to the excerpt and body:

<! -- this article has an excerpt -- >
<div class="excerpt">
<txp:excerpt />
</txp:if_excerpt />
<div class="body">
<txp:body />

The same txp:if_excerpt tag can be used on the list page to handle articles that have no Excerpt set. For example, to display the article Body when the Excerpt is empty:

<! -- the article has an excerpt -- >
<txp:excerpt />
<txp:permlink>read more</txp:permlink>
<txp:else />
<! -- there is no excerpt -- >
<txp:body />

If you need to automatically generate an Excerpt from the Body, there are several plugins that will help. You’ll find them at Textpattern Resources or on the Textpattern Plugins Forum.

How do I use a different page layout for individual articles and article lists?

Use <txp:if_individual_article> </txp:if_individual_article> and <txp:if_article_list> </txp:if_article_list> in your page template or form.

How do I use a different page layout for each section?

Create multiple templates in presentation > pages, then change the “Uses page:” option for each section in presentation > sections.

You can also select the CSS stylesheet individually for each section.

How do I select which form is used to display articles?

The form used to display articles is specified by the <txp:article /> tag in your page template. In the default template it looks similar to this:

<!-- center -->
<div id="content">
<txp:article />

To display articles using a different form, change the <txp:article /> tag to specify the form name like this:

<txp:article form="myform" />

If no form="..." attribute is specified, <txp:article /> will look for an article from named “default”.

You can specify separate forms for list pages and individual article pages like this:

<txp:article listform="short" form="long" />

It’s also possible to use a different form for a single article, using the Override form selection under Advanced Options on the content > write page.

How do I change the grey line separating articles?


How do I change the layout of an article?


The layout of each article is controlled by a form. Go to textpattern > presentation > forms and edit the one used by your page template (probably ‘default’, unless you’ve changed it).

Alternatively, you can create a new article form and use that to display articles. For more information, see ‘How do I select which form is used to display articles?’