Multi-lingual blog – taxonomy – Tarski theme display

As you might have seen, I am writing this blog in a few languages, mostly English of course, but also German (my mother tongue), Italian (where I lived for 2.5 years), and recently I try also to write a bit in Japanese (where I live now). I was searching for a simple solution to tag my posts with a language, and also display the respective language in the excerpt and post header (at least in the theme Tarski I am using). Since most of the solutions out there are much more involved, including translations support (which I will not do), I just came up with a simple solution (see the red marks in the screenshot):

language tagging

Setting up taxonomy

First step is to add a new taxonomy. The WordPress Codex starts by saying

Taxonomy is one of those words that most people never hear or use. Basically, a taxonomy is a way to group things together.

Well, yes, it is about defining a new way to categorize things. In my case, language of the post. The above page then continues in describing programmatical ways to add custom taxonomies, which I am not very familiar with. Fortunately there are a few plugins that allow creation of taxonomies in a user friendly way. I mention two: Ultimate CMS and Types. I am using the former by now, but due to some points I think about switching to the later, but see later about that.

Using Ulimate CMS one first activates the Taxonomy Manager, then adds one taxonomy language. I decided for the following options (only the most important for me mentioned):

  • Associated post types: Posts, Pages
  • Hierarchical: False
  • Slug: language

After that I added terms, i.e., languages to the taxonomy: Deutsch, English, Italiano, 日本語, giving them the ISO two letter codes as slugs (i.e., de, en, it, ja).

The Ultimate CMS comes with a widget to select posts according to a custom taxonomy, but I decided for a different plugin: List Custom Taxonomy Widget which adds the ability to show the count of posts in the respective language.

Displaying a short code in the post header

(Update: see this post for how to show flags instead of language short codes!)

I have never written a plugin for WordPress, or Tarski (the theme I am using), but using a bit of grepping through the source and looking at the generated HTML code, together with examples from the Tarski web site, I managed to create a view lines of php code that achieves putting the short code (ISO, or slug) of the respective language in the meta-data header. The full source code of the plugin is here:

ID, 'language', array("fields" => "all"));
    $first = true;
    foreach ($term_list as $term) {
      if (!$first) {
        $metadata .= ', ';
        $first = false;
      }
      $metadata .= '' . $term->slug . '';
    }
    $metadata .= ' | ';
    return $metadata;
}

add_filter('th_post_metadata', 'add_language_to_metadata', 0);

?>

Putting this file as tarski-meta-post-language.php into the folder wp-content/plugins/tarski-meta-post-language/ on your blog side allows you to activate it in the plugin setting. But do this only if you are using the Tarski theme, I don’t know what will happen if another theme is used.

Comments and suggestions about how to achieve this in a simpler way are welcome!

Leave a Reply

Your email address will not be published. Required fields are marked *