Fix the problem of language recognition

Finally, I’ve fixed the problem of language recognition.

Before, my site can not filter the posts very well in a language which is determined by the browser’s language setting to show on the homepage.
When I use the code :
<?php if ($_SERVER[“HTTP_ACCEPT_LANGUAGE”] != “zh-CN”) {query_posts(‘cat=57,16′);} ?>
in homepage, the posts can be filtered correctly in IE7: If your browser’s language setting is zh-CN, the homepage will show all the posts, else, the homepage will show all the posts in category ID 57/16.
But in IE6 or FireFox, it doesn’t work. Because the browser’s language setting is “zh-cn”, it’s not “zh-CN”.

So I added a condition :
            if (($lan != “zh-CN”)&&($lan != “zh-cn”)) {query_posts(‘cat=57,16′);}

Maybe it is not very “beautiful”, but it works very well for me! So hope it can help you! Maybe one day, I can make it smarter!

Ps: The codition part is a general format in PHP code, but the execute part is only for WordPress!

Leave a Reply

↑ Back to top