當(dāng)前位置:首頁(yè)>WordPress建站>WordPress開(kāi)發(fā)>獲取多站/多語(yǔ)種 ( 基于 WPML ) WordPress 網(wǎng)站當(dāng)前的語(yǔ)種

獲取多站/多語(yǔ)種 ( 基于 WPML ) WordPress 網(wǎng)站當(dāng)前的語(yǔ)種

某項(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;
    }
}
聲明:本站所有文章,如無(wú)特殊說(shuō)明或標(biāo)注,均為本站原創(chuàng)發(fā)布。任何個(gè)人或組織,在未征得本站同意時(shí),禁止復(fù)制、盜用、采集、發(fā)布本站內(nèi)容到任何網(wǎng)站、書(shū)籍等各類媒體平臺(tái)。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。

給TA打賞
共{{data.count}}人
人已打賞
歡迎關(guān)注WordPress大學(xué)公眾號(hào) WPDAXUE
WordPress開(kāi)發(fā)

正確加載 CSS 到 WordPress

2014-7-1 8:39:21

WordPress開(kāi)發(fā)

創(chuàng)建一個(gè) WordPress 自定義注冊(cè)表單插件

2014-9-30 9:30:26

4 條回復(fù) A文章作者 M管理員
  1. 請(qǐng)問(wèn)有設(shè)置獲取訪問(wèn)者的ip來(lái)判定訪問(wèn)者的國(guó)家,讓網(wǎng)站自動(dòng)展示某一國(guó)家的語(yǔ)言呢?

  2. 請(qǐng)問(wèn)下怎么在文章頁(yè)里添加個(gè)鏈接,點(diǎn)擊這個(gè)鏈接可以下載指定的附件(excel)?

    • 解決了,原來(lái)挺簡(jiǎn)單的,是自己想復(fù)雜了。

  3. coolwp.net

    !emptyempty
    應(yīng)為
    !empty

?
個(gè)人中心
購(gòu)物車
優(yōu)惠劵
今日簽到
有新私信 私信列表
搜索

永清县| 武功县| 洪湖市| 吉安市| 江源县| 西和县| 张家川| 原阳县| 葵青区| 洞头县| 浦北县| 瑞丽市| 昔阳县| 鸡东县| 平和县| 沾化县| 翁源县| 荃湾区| 台江县| 井研县| 青神县| 乡城县| 兴国县| 从化市| 阿克陶县| 社会| 高邮市| 逊克县| 东兴市| 平塘县| 海原县| 凤翔县| 中阳县| 新野县| 广灵县| 青浦区| 元氏县| 普定县| 合作市| 广东省| 玉树县|