Monthly Archives: February 2014

From gengo to polylang: updating the theme

So I postponed hacking a mode with multiple languages on the same page and decided to set polylang on my production site (hem) my blog.

But Gengo was using some customized template tags so the theme was adapted to it and this needed to be changed.

With polylang it’s a lot simpler, all navigation is handled by filters, so only thing really custom had to be written:

Basically my hacked version of the_translations had to be ported. And to keep it simple it can even be part of the functions.php file in the theme and use the pll_the_languages function.
I want to display the other language title prefixed by “Language version” written in this language. As the gettext like functions would only return strings in the current language, I hardcoded those strings, but adding them in Polylang admin “strings translation” would have been nice…
So here is the code:

 $translation_title=array(
    'en' => "English version:", 
    'fr' => "Version française : ");
function my_translations() {
    global $post;
    global $translation_title;
    $post_id=$post->ID;
    if ( function_exists('pll_the_languages') ) {
        $translations = pll_the_languages(array('post_id' => $post_id, 'hide_if_no_translation'=>1, 'hide_current'=>1, 'raw'=>1));
        if(!empty($translations)) {
            foreach($translations as $tr) {
                $trid=pll_get_post($post_id, $tr['slug']);
                ?><li lang="<?php echo esc_attr($tr['slug']);?>"><?php echo $translation_title[$tr['slug']]; ?><a hreflang="<?php echo esc_attr($tr['slug']);?>" href="<?php echo esc_url($tr['url']);?>" rel="alternate"><?php echo get_the_title($trid); ?></a></li><?php
            }
        }
    }
}

Instead of porting the old theme, I did build a new one based on WordPress’ Twenty Twelve updated with my previous header and dark color scheme.
I also played with a few css3 features for more neon light effects 🙂

And here it is !