On one of my domains I installed WordPress MU a few days ago. There will be a German and an English blog, which both have the same content and are also the same theme. In WordPress MU, it is possible to choose a separate blog for each language.
Now I’m creating the theme. It is located quite normal, so it is available for German and English. But there will be areas that I do not want translated because, for example the sentences are too long and the language files would unnecessarily bigger. Another stumbling block is also the site navigation. If I want to exclude certain pages from the menu, I have a problem because the id’s of pages from the one blog are not the same as in the other blog. But I want to keep the maintenance effort for the theme as low as possible and not requiring to do any changes in the code or the CSS into 2 themes (horrible!).
And I’ve come to the following solution: Every blog has an ID. Let’s say that English blog has the ID 1 and the German blog the ID 3. You create 2 files for just such snippets, for example en_navigation.php and de_navigation.php, in which the different requirements are included. Now, these files must be included in your blog. For this purpose we write a small function.
function di_get_preffix() {
global $blog_id;
if((int)$blog_id === 1) {
return 'en';
}elseif((int)$blog_id === 3){
return 'de';
}
}
Now you can add your files at any point in your templates with the function call.
include TEMPLATEPATH . '/' . di_get_preffix() . '_navigation.php';
I abandon the if (file_exists (…)) , as you should be able to control it in your blog.
Comments
2 responses to “WordPress MU – embed language-dependent templates”
Interesting solution. You could also use child themes:
In each theme, in functions.php, define a constant, for example:
define('THEME_LANG', 'de');
Also a nice idea. Thanks scribu!