Textpattern as a complete CMS

As part of my uni project, I have been implementing textpattern as a complete Content Management System. Due, to the fact, that when I was doing this I couldn’t find any information about it, I have decided to document how I did it.

Information Architecture

Before installing textpattern, I worked out the IA for the website in question (meaning what categories and sub-categories were necessary), so that, when it came to mapping that to textpattern it wouldn’t be so hard (yeah right!)

Section Vs Categories

My first thought was to turn-off sections and just use categories. So that a subfolder e.g. site.com/about/ would be a category called about and site.com/about/staff/ would be two categories about and staff. This presented a problem because textpattern stopped linking to the pages properly. It started missing out the site name in the URL so I was getting site.com/article/3/. Also when I opened site.com/?c=about&c=staff I was shown the relevant articles but no way to get to a perma-link of these articles including the relevant categories in the URL.

So I decided to use sections and not categories; to be honest, I don’t understand how categories work or if they do at all in textpattern. By using sections, it meant I was going to have to remove the article ID from the URL and also forfeit a site structure going more than 2 folders deep e.g. I couldn’t have site.com/about/staff/john/ or site.com/about/staff/mary because John and Mary would have to be on the same page.

People have said categories are good for making category specific lists and sections are responsible for how the page appears. If it were up to me, then, sections wouldn’t have an influence over the URL structure as they do. The problem with sections and categories, when it comes to using textpattern as a CMS is that novice users will probably not understand/be bothered to use both and so, one must fall by the wayside, and as sections are necessary it’s bye-bye categories for now.

The less pages the better

If you haven’t already realised, with a dynamic site the whole point is that fewer templates are used and few pages look like many. Out of the box, it is a hard thing to achieve with textpattern but, there is a solution, in the form of a plug-in, works like a dream. Just install the plug-in from here, activate it and use it in your page templates. This means you can use it like a if statement in PHP;

e.g. if (section="x") {don’t display link to section x}

Before I was aware of this plug-in, there wasn’t a way to dynamic change issues such as the navigation menus. Nielsen says you shouldn’t have a link to the current page but, without this plug-in it’s hard for textpattern to achieve.

Static pages

Textpattern is great for dynamic blog like pages but what about static pages like an about us or a contact page? A solution, garnered from someone with greater wisdom than myself, is to create a section called static and assign these about/contact/accessibility statement pages to be articles in this section. Once this has been done you will have something like site.com/static/17/contact this can be made friendlier with mod_rewrite.

RewriteEngine On
RewriteRule ^contact/$ /static/17/contact [L]
RewriteRule ^contact$ /static/17/contact [L]

Then in your page template simply link to the page as so

<a href="/contact/"            >contact us</a>

and hey presto the world is in order once more.

Of course, this static page fix means you can’t use the if section plug-in to dynamically modify the page, as they are in the same section. This is an unfortunate but necessary evil.

Displaying specific articles on pages

A CMS requires you to be able to display specific articles on all if not some pages, i.e. the site may need advertising to be displayed on all pages. So how would we achieve that?

A little PHP in an external file goes along way. Create your article in a section called adverts and call it something like advert 1, remember, novices will be updating this and may want to change the context of the advert every so often so it is best to call it what it is. Place the advert title inside a heading in the article body along with the actual advert. Then with some PHP/SQL drag that article’s body_html out so you can display it.

 $hostname_textpattern = "localhost";
$database_textpattern = "<>";
$username_textpattern = "<>";
$password_textpattern = "<>";
$textpattern = mysql_pconnect($hostname_textpattern, $username_textpattern, $password_textpattern) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_textpattern, $textpattern);
$query_get_advert1 = "SELECT Body_html FROM textpattern where id= 5";
$get_advert1 = mysql_query($query_get_advert1, $textpattern) or die(mysql_error());
$row_get_advert1 = mysql_fetch_assoc($get_advert1);
$totalRows_get_advert1 = mysql_num_rows($get_advert1);
echo $row_get_advert1['Body_html'];
mysql_free_result($get_advert1); ?>

This snippet can be used to get an article’s body just by changing the id. Save the file as whatever you like e.g. get-advert1.php and place the following in your page template.

It is important to note that, the PHP only gets the body of the article, if it got the title as well then your page would display Advert 1 on it and that would suck. It is far better to give the article the user-friendly title of Advert 1 but, you must hide this from your website’s users, and put the advert’s title inside the main body of the article so that it shows as well.

Other customisations

There are numerous other customisations and modifications that must be made to textpattern to make it a more accessible/usable/standards-compliant piece of kit.

Out of the box, the textpattern search box doesn’t come with a search button unless JavaScript is turned off. This is shit usability and as such must be fixed and here is how. Open up textpattern>publish>taghandlers.php and on line 505 comment out;

$sub = (!empty($button)) ? '<input type="submit" value="'.$button.'" />' : '';

And, underneath it, add

$sub = '<input type="submit" class="button" value="Search" />';

If you wish to add a proper label to the form just comment out

$out = (!empty($label)) ? $label.br.$out.$sub : $out.$sub;

And, underneath it, add

$out = (!empty($label)) ? '<label for="search-input" class="hide">'.$label.'</label>'.$out.$sub : $out.$sub;

I added the class of hide to the label as I wanted to hide it from screen media and only display it to screen-readers. I also added an id to the search form by modifying the line;

return '
<form action="'.$pfr.'index.php" method="get">'.$out.'</form>';

to

 return ' <form action="'.$pfr.'index.php" method="get" id="searchform">'.$out.'</form>';

When you modify textpattern’s source, make sure you heavily comment what you have done, because updating to the next textpattern version would be a nightmare if not. You may even wish to make a copy of the original source as a back-up. Lots of people recommend this, but I’ll be honest, I never do.

You can also make textpattern’s search function more user-friendly by following Justin French’s A Better Textpattern Search tutorial.

I chose not to allow comments on my implementation but, others may wish to have comments; if you want comments you’ll need to modify the relevant form to have labels, and to remove tables from the form.

Update – 12/06/2006

I now use WordPress on this blog and advocate its use for both blogs and non-blogs sites as it is very user friendly. I hope to write this opinion up a little more at some point.

3 responses to “Textpattern as a complete CMS”

  1. I still have to read this thoroughly, but thanks for writing this! I’m just starting with Text Pattern and am finding myself lost. I’ve never done any CMS before but am finding myself needing to do it for client work at my new job. I’ve never used a database and it’s all new to me. I hope this helps. Thanks again!

  2. kyra, and anyone else, this article is quite old. I don’t recommend these at all, particularly because there are ways to do these things without hacking.

    “The less pages the better…”

    http://textbook.textpattern.net/wiki/index.php?title=Txp:if_section

    “Static pages…” and
    “Displaying specific articles on pages…”

    http://textbook.textpattern.net/wiki/index.php?title=Txp:article_/

    “Other customisations…”

    http://textbook.textpattern.net/wiki/index.php?title=Txp:output_form_/
    http://textbook.textpattern.net/wiki/index.php?title=Txp:site_url_/

  3. As Mary states, this article is quite old. So don’t take it word for word. For all I know textpattern has come along way in 2 years.