Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save roelven/395493 to your computer and use it in GitHub Desktop.
Save roelven/395493 to your computer and use it in GitHub Desktop.
Function to get content in a particular language when dependant on qTranslate
// Function to get content in a particular language when dependant on qTranslate
// qTranslate plugin for Wordpress: http://www.qianqin.de/qtranslate/
// Inspired by http://stackoverflow.com/questions/1853406/simple-regular-expression-to-return-text-from-wordpress-title-qtranslate-plugin
function ynbs_translatethis($content) {
$regexp = '/<\!--:(\w+?)-->([^<]+?)<\!--:-->/i';
if(preg_match_all($regexp, $content, $matches)) {
$output = array();
$count = count($matches[0]);
for($i = 0; $i < $count; $i++) {
$output[$matches[1][$i]] = $matches[2][$i];
}
return $output;
} else {
echo 'no matches';
}
}
$post_title = "<!--:en-->English text<!--:--><!--:it-->Italian text<!--:-->";
$string = ynbs_translatethis($post_title);
print $string['en'];
print $string['it'];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment