Created
May 9, 2010 23:14
-
-
Save roelven/395493 to your computer and use it in GitHub Desktop.
Function to get content in a particular language when dependant on qTranslate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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