Managing static pages with Textpattern.
A common beginner’s question about Textpattern is how to manage non-blog content, like an “about” page, or a collection of documents. This is quite easy to achive, though not entirely obvious to a first time user. Below are some layouts that might help beginners; experienced users will probably want to skip this one.
First, it helps to understand how Textpattern organises content. Articles are documents that have a title, body and author, plus some optional fields like excerpts, categories, comments and so on. Sections are divisions within the web site that contain articles. Each article is contained within exactly one section. Depending on the url mode selected in your Textpattern setup, section URLs look like1 http://example.com/mysection/ or http://example.com/index.php?s=mysection.
The way a section is displayed is determined by Page templates and article Forms.
A normal Textpattern blog-style section uses a page template that displays a list of articles (<txp:article limit=5 />), and an article form that displays the article’s title, permlink, date, author, body and comment link.
To display static or non-blog content, all we need to do is use an article form that leaves out unnecessary features like comments, and change the page layout to suit. We can then use the Textpattern article interface to create and edit content.
The Article Form
The default Textpattern article form looks something like this:
<h3>
<txp:permlink><txp:title /></txp:permlink>
·<txp:posted />
</h3>
<txp:body />
<p>
<txp:comments_invite />
</p>
* * *
This template is used to display the list of articles in a list on the section page, and each individual article on its archive page. It’s a nice simple layout for a blog, but not quite what we want for our static content. Create a new form:
<h3><txp:title /></h3>
<p><i><txp:excerpt /></i></p>
<txp:body />
Set the form type to “Article”, and save it as “static_article”.
This gives an article layout that’s much closer to what we need: the comments are post date are gone, and the article excerpt – if any – is displayed at the top of the article, just under the heading. You can leave out the excerpt part if you don’t plan on using it.
We can use this form to display all our non-blog content, whether it’s a simple “about” page or one of a series of articles.
Now create a second form:
<h4><txp:permlink><txp:title /></txp:permlink></h4>
<p><txp:excerpt /> <txp:permlink>(read more..)</txp:permlink></p>
Set the form type to “Article” again, and call this one “static_headline”.
We can use the headline form to display a list of articles in a section that contains several articles (a collection of recipes or tutorials, for example).
Next we need to create page layouts that use these forms.
The Page Template
We’ll set up two different page templates here: one for an “about” section that contains only a single article; and one for a “recipe” section that contains many articles (you can change these names to something more appropriate for your own web site, of course).
In the Presentation/Page section of the administration interface, select the “default” template, and copy it twice: once as “static_page”, and again as “static_list”.
In “static_page”, look for the <txp:article /> tag, and change it to this:
<txp:article limit=1 form="static_article" />
We’ll use this to display our “about” page, which contains only a single article (hence “limit=1”).
Now edit the same tag in “static_list”:
<txp:article limit=100 form="static_article" listform="static_list" />
This will display a list of article titles and excerpts, as defined in the static_list form, and also handle displaying the article body when the user clicks on a title.
Finally, we need to set up our sections to use the correct page layouts.
The Section
First, the about section. Textpattern should already have a section named “about”, so we can use that. In the Presentation/Sections tab of the administration interface, select the following settings for “about”:
Now create a new section called “recipe”, and change its settings:
If there’s a red exclamantion mark shown beside the section name, you’ll need to click on it and follow the instructions.
All that’s left now is to write some content.
Post an article in the “about” section; it’ll be available at the URL http://example.com/about/ (or http://example.com/index.php?s=about, if you’re using messy URLs). The article title will become a heading on that page, and the body is its content.
Articles posted in the “recipe” section will show up in a list at http://example.com/recipe/ (or http://example.com/index.php?s=recipe). Clicking on the article heading or “read more..” will take the user to the full article page.
If you’d like to add further sections for static content, there’s no need to create new forms or pages, unless you’d like to lay them out differently. Just create a new section, using the same settings as “about” or “recipe” above, depending on whether it’s a single page or a list.
Customizations
Finally, here are a few quick enhancements you might consider.
If you’d like to enable user comments on your recipe pages, you’ll need to change the settings in the Preferences tab if necessary, and add this tag at the bottom of your static_article form:
<txp:comments_invite />
You can disable comments on the “about” page just by setting “Comments: off” in the article editor.
To sort the recipe list alphabetically, rather than by date, requires a little trickery. Change the static_list page template like so:
<txp:if_article_list>
<txp:article_custom limit=100 sortby="title" form="static_list" />
</txp:if_article_list>
<txp:if_individual_article>
<txp:article limit=1 form="static_article" />
</txp:if_individual_article>
Bear in mind however that this method has some disadvantages. article_custom doesn’t support browsing by category or page, so these features won’t work in your recipe section using the above template. Make sure limit is large enough to include all articles in the section.
The article links on the recipe list page show the tooltip text “Permanent link to this article” by default. To change this, install the zem_link plugin, and change your static_headline form to look something like this:
<h4><txp:zem_link title="link to '%s'"><txp:title /></txp:zem_link></h4>
<p><txp:excerpt /> <txp:zem_link title="read the full article">(read more..)</txp:zem_link></p>
If you’d like your recipe articles to be available to RSS and Atom subscribers, simply set “Syndicate” to Yes in the section settings.
1 “clean” URLs require some additional magic with .htaccess and section files, which are outside the scope of this article. If you’re having trouble with 404 errors or pages that show the wrong content, test in Messy URL mode first.
14 September 2004, 05:02 by zem ·
Commenting is closed for this article.
— Dan Sep 14, 08:39 am #
— Joni Sep 14, 11:27 am #
I have a section ‘journal’ (which of course is my blog area) on my site and it uses a page template ‘journal’. My article TXP tag is now using the default form (which i had already modified). Now, my permlink tag points to a single article page (together with the comment list and comment form) when i clicked it, and this page still uses the default form. Is it possible if I would like to use another customized form (say, I call it ‘single’) for my single article (permanent link) page? I would rather not want to create another section just for this, everything under section ‘journal’ would be good.
I know does not take an attribute like form=”single” or listform=”single”, so how do I go about this, zem? Appreciate your help to solve this problem, or perhaps a different suggestion? (if this is impossible).
Thanks in advance!
— john Sep 16, 10:59 am #
What were the tags txp:if_article_list and txp:if_individual_article for???
Anyway, i love the zem_links tag. Great stuff!!
— john Sep 16, 02:20 pm #
very clear and it works perfectly.
only one question : is there a txp tag for generationg a link to the static page ?
if i use
http://example.com/index.php?s=about(because i am now using messy url patterns, i will have to modify this later …a txp tag could handle this no ?
thanks
— luro Nov 23, 08:09 pm #
if i use the < txp:comments_invite />@ tag to allow visitors commenting the about page (as describe below) i only have a link to the comment form (as in a usual article list).
How to have directly in this same page : the one article of the section, all the comments and the comment form ? I can’t find out !
— luro Nov 24, 12:20 am #
I did everything in the tutorial, but the “recipe” section does not display as a list of articles. I got the static_page to work correctly, but not static_list.
I’m using TXP 1.0rc1
Help?
— Paul Jan 4, 02:17 am #
<txp:article limit=100 form="static_article" listform="static_list" />
right?
thanks
— ingrid Jan 31, 11:20 am #
Creating a Static Page with TextPattern
— Thomas Feb 25, 05:12 am #
Smashing article, but I’m using RC3 and can’t seem to get it work. I think it’s to do with the .htaccess file and new way of using URLs. I can see the full article by going to /section/article-no/article-name , but not by going to /section alone. Any suggestions?
— Ben Brundell Mar 8, 07:16 am #
Using RC3, I’ve solved the problems above. Firstly, I’ve used the built-in tag generator to re-generate the txp: tags.
Instead of …
txp:article limit=1 form="static_article"... use …
txp:article form="static_article" limit="1",And instead of …
txp:article limit=100 form="static_article" listform="static_list"... use …
txp:article form="static_article" limit="100" listform="static_headline"I appreciate the differences are minimal (just the order of arguments, and the use of
static_headline, rather thanstatic_list) but on RC3 it means the difference between working and blank pages.Thanks again for the great article, and to Dean for making the thing so easy that I, a novice, can update something as slick as this!
— Ben Brundell Mar 8, 07:41 am #
It was getting difficult for me to understand how to create static pages, but now it’s clear, thanks to you.
— Paulo Baptista Mar 10, 11:24 am #
— Paul Takemura Apr 22, 04:32 pm #
After reading your “static pages” info (great, btw) I’m left with the question: how do I make a home page (default, or what comes up at ‘http://www.mysite.com/index.php’) with static articles (or specific articles) and also have a standard “blog” that lists all recent articles?
— Rich Webster Apr 25, 12:04 pm #
Thank you so much for this article. I was going nuts with this problem. Looks obvious to say but not to do.
— neocorsten Aug 22, 06:51 pm #
plz. help me to get my static info once again
— Rosalita G. Bonifacio Nov 19, 08:05 pm #
Hello, great article !!!
I’d buy you some amazonian hax if I could!:)
— 10 Reasons to Date Jun 3, 06:06 pm #