Content last modified Tuesday 24 August 2021
hop to #bottom
Damelon Kimbrough
About It:
Rate it:
  • Helpful?
  • 1 Yes
  • 2 No
Flag it:

If you'd like to provide updated information and do not have access to directly edit, please contact the site admin; thanks!

Bilingual in Textpattern

A Canadian blogger of my acquaintance who is working on his own Textpattern install inquired as to how I make my bilingual categories work on my personal site: damelogue. This will be my attempt to explain it.

My basic goal was to allow for a meaningful division of materials using only two categories (the Textpattern default). Generally by language and more specifically by topic.

I’ve more than less arranged this article in the correct order of execution using the sections of the TXP control panel as headers. Your milage may vary.



screenshot of organize tab in TXP γ1.19

First, on the ‘organize’ tab I created the beginning Article Categories I wanted to use. One for each language (en, fr) and then also some to deal with the topics, in my case (apnea, coupe-de-gueule, dirty-laundry, etc.).

You will note that in the above categories any that are multiword I have hyphenated. This is not strictly necessary, but below I explain why I do it.


screenshot of write tab in TXP γ1.19

Then, go to your ‘write’ tab and assign categories to your articles. I suggest that you always use category 1 for topic and category 2 for language (I will explain why at the end of this document).



On the ‘forms’ tab I created a form (I don’t think it makes any difference what form type you choose, link or misc. I chose link) named ‘archives’ and put the following in it :

<h3>Par catv&#169;gorie</h3>
<h4>En anglais</h4>
<li><a href="/?c=apnea">Apnea</a></li>
<li><a href="/?c=dirty-laundry">Dirty laundry</a></li>
<li><a href="/?c=ethnoblogy">Ethnoblogy</a></li>
<li><a href="/?c=leftovers">Leftovers</a></li>
<li><a href="/?c=living-in-france">Living in France</a></li>
<li><a href="/?c=rants">Rants</a></li>
<li><a href="/?c=reflection">Reflection</a></li>
<li><a href="/?c=the-great-fry-war">The great fry war</a></li>
<h4>En franv&#223;ais</h4>
<li><a href="/?c=coupe-de-gueule">Coupe de gueule</a></li>
<li><a href="/?c=distractions">Distractions</a></li>
<li><a href="/?c=ethnoblogie">Ethnoblogie</a></li>
<li><a href="/?c=la-vie-en-france">La vie en France</a></li>
<li><a href="/?c=le-reste">Le reste</a></li>
<li><a href="/?c=reflexion">Reflexion</a></li>
<li><a href="/?c=remy">Rv&#169;my</a></li>
<h3>Tous les articles</h3>
<li><a href="/?c=en">En anglais</a></li>
<li><a href="/?c=fr">En franv&#223;ais</a></li>

Why did I do it this way? Well, currently if you let Textpattern handle the link output automatically your links end looking like so : /?c=the%2great%2fry%2war instead of /?c=the-great-fry-war which I not only think looks nicer but is easier to use if someone wants to link to a category. Also, I think I have set this up in such a way that if Dean eventually implements a URL-only title scheme for categories when you change everything you will be able to maintain the exact same output urls which makes for better continuity.

If all of your categories are single words, then this aspect of my setup is probably pointless and extra work for you.


Finally on the ‘pages’ tab in my default template I put the output tag in my template where I wanted the list to appear : <txp:output_form form="archives" />

You should now have categories that are searchable by language and/or topic (after a fashion anyway).

Related Articles

Okay, so that part is fairly straight forward. But I also wanted to be able to display a list of ‘related articles’ on my individual article pages (see the left column here for an example). My problem was that when I did that my results always ended up with a list done by language only. I don’t know why, I did try to find out, but the answer is either beyond me or no one understood my question. Anyway, here is how I solved it.

Warning : Only read beyond this point if you want to risk destroying your install and causing the deaths of thousands of innocent kittens.

Okay, if you are willing to risk the kittens go to : /textpattern/publish/taghandlers.php

Line 345 and change :

$cats = safe_row("Category1,Category2","textpattern", "ID='$id' limit 1");

to this :

$cats = safe_row("Category1","textpattern", "ID='$id' limit 1");

Lines 350 and 351 and change :

(!empty($cats [0])) ? "and ((Category1='$cats [0]') or (Category2='$cats [0]'))" :'',
(!empty($cats [1])) ? "or ((Category1='$cats [1]') or (Category2='$cats [1]'))" :'',

to this :

(!empty($cats [0])) ? "and ((Category1='$cats [0]'))" :'',
(!empty($cats [1])) ? "or ((Category1='$cats [1]'))" :'',

In the above two lines of code it was necessary to add one space between $cats and the bracketed number [0 or 1] because Textile is overenthusiastic in its task and that was the only way to stop it from converting those two lines of code to multiple links. I also did not preserve tab spaces to the left of these examples. Make your alterations at the same depth in the code and be cautious of spacing! In this example it may appear that these lines wrap, but in reality lines 345, 350, and 351 are all single lines in the file.

Now your TXP install will only pull results from Category 1 for inclusion in a related articles list. In truth all I’ve done is remove Category2 from the equation. When I asked Dean about this, he said a future release would allow for setting a preference for this in lieu of needing to hack the file.

Now on your individual article page template put the following wherever you want the list to appear :

<h2>v&#196; lire aussi</h2>
<txp:related_articles limit="10" break="li" />

Please note that I have included the extra <li> line with a non-breaking space because on the occasion that you don’t actually yet have any other articles in the category in question TXP will not output an empty set of <li> tags. And a <ul> list without any <li> tags will break your validation. There is probably a trickier way to accomplish this, but I don’t know it.

Now you should have either have a semi-bilingual TXP categories section and relevant related articles listings or the police are searching for a vicious kitten killer: you.

I make no claims that this is the definitive way to approach or solve this question. This is just what I did.

Thanks to Damelon for providing this article, thanks to Jakob for requesting it, and thanks to Manfre and Andrew for making it viewable.

Article Request Count:
Initially released:
2004-06-09 04:29:00
Posted here:
11 Feb 2005

You know you want to visit the Archives.
Published with Textpattern