某項(xiàng)目需要獲取當(dāng)前網(wǎng)站的語(yǔ)種(基于 WPML 的多語(yǔ)種網(wǎng)站),如果僅僅是 WPML 的話,使用其定義的常量 ICL_LANGUAGE_CODE 即可獲取當(dāng)前的語(yǔ)種代碼,問(wèn)題是如果 WPML 未啟用呢?網(wǎng)站架構(gòu)是多站呢?度娘和谷哥都沒(méi)給出答案,看來(lái)不能偷懶了。
作用與用途在說(shuō)明中已經(jīng)說(shuō)的夠清楚了!這里就不再多說(shuō)啥了。
How to get the wordpress current languange attribute? the answer is here!
Getting the current language attribute of your wordpress website based on WPML or none,compatible with multi-site architecture.
/**
*作用:返回基于WPML的多語(yǔ)種網(wǎng)站當(dāng)前的語(yǔ)種,如果WPML未啟用,則返回其默認(rèn)語(yǔ)種的code,兼容多站;
*用法:
*$get_lang_attr = new GET_LANG_ATTR();
*$get_lang_attr=$get_lang_attr->cwp_get_current_lang_attribute();
*echo $get_lang_attr;
*作者:suifentgec
*/
class GET_LANG_ATTR{
public function is_someone_plugin_activated($plugin_name){
$plugin_name=trim($plugin_name);
if(!empty($plugin_name)){
$active_plugins = (array) get_option( 'active_plugins', array() );
if ( is_multisite() )
$active_plugins = array_merge( $active_plugins, get_site_option( 'active_sitewide_plugins', array() ) );
foreach ( $active_plugins as $plugin )
if ( strpos( $plugin, $plugin_name ) ) return true;
return false;
}else{
return false;
}
}
public function cwp_get_current_lang_attribute(){
$is_wpml_activated=$this->is_someone_plugin_activated('/sitepress.php');
if($is_wpml_activated){
global $sitepress;
$languge_attribute=$sitepress->get_current_language();
}else{
$languge_attribute=get_bloginfo( 'language' );
}
return $languge_attribute;
}
}






請(qǐng)問(wèn)有設(shè)置獲取訪問(wèn)者的ip來(lái)判定訪問(wèn)者的國(guó)家,讓網(wǎng)站自動(dòng)展示某一國(guó)家的語(yǔ)言呢?
請(qǐng)問(wèn)下怎么在文章頁(yè)里添加個(gè)鏈接,點(diǎn)擊這個(gè)鏈接可以下載指定的附件(excel)?
解決了,原來(lái)挺簡(jiǎn)單的,是自己想復(fù)雜了。
!emptyempty
應(yīng)為
!empty