programing

언어 WPML 숨기기

bestcode 2023. 2. 14. 20:22
반응형

언어 WPML 숨기기

는 WPML 언어를 사용하고 있으며, 다음 사항에 대한 해결책을 찾을 수 없습니다.

언어를 숨기고 싶은 언어 전환기에서 예를 들어 "he"라고 합시다.현재 언어가 "ar"라고 하면 아랍어 사이트에서 히브리어를 셀렉터에 표시할 수 없습니다.히브리어에서도 마찬가지입니다.

줄여서 말하자면, 내가 원하는 것은 - 만약 우리가 아랍 사이트에 있다면 - 히브리 국기는 숨겨질 것이다.

내가 시도한 것:

function language_selector_flags(){
    $languages = icl_get_languages('skip_missing=0');
    if(!empty($languages)){
       if(ICL_LANGUAGE_CODE=='en') 
       {
$order = array('ar'); //Specify your sort order here
       }
elseif(ICL_LANGUAGE_CODE=='he')
{
$order = array('en', 'ar'); //Specify your sort order here
}

        foreach ($order as $l) {
            if (isset($languages[$l])) {
                $l = $languages[$l]; //grab this language from the unsorted array that is returned by icl_get_languages()

                //Display whatever way you want -- I'm just displaying flags in anchors  (CSS: a {float:left; display:block;width:18px;height:12px;margin:0 2px;overflow:hidden;line-height:100px;})
                if($l['active']) { $class = "active"; $url=""; } else { $class = ''; $url = 'href="'.$l['url'].'"'; }
                echo '<a '.$url.' style="background:url('.$l['country_flag_url'].') no-repeat;" class="flag '.$class.'">';
                echo $l['language_code'].'';
            }
        }
    }
}

실렉터에는 전혀 영향을 주지 않습니다.

플러그인 WPML Flag In 메뉴를 확인하실 수 있습니다.

를 사용할 수 있습니다.plugin_wpml_flag_in_menu()플러그인에서 기능(여기 소스 코드 참조)하고 다음을 바꿉니다.

// Exclude current viewing language             
if( $l['language_code'] != ICL_LANGUAGE_CODE )
{
    // ...
}

와 함께

// Include only the current language                
if( $l['language_code'] == ICL_LANGUAGE_CODE )
{
    // ...
}

현재 언어/플래그만 표시합니다.

ps: 추가 지원이 필요한 경우 이 디버깅 함수의 액티브한 언어 출력을 확인할 수 있습니다.

function debug_icl_active_language()
{
    $languages = icl_get_languages( 'skip_missing=0' );
    foreach( (array) $languages as $l )
    {
        if( $l['active'] )
        { 
            printf( '<pre> Total languages: %d - Active: %s </pre>', 
                    count( $languages ), 
                    print_r( $l, TRUE ) );
        }
    }
}

도움이 되는 링크가 있습니다.먼저 확인해 주세요.

http://wpml.org/forums/topic/hide-language-vs-display-hidden-languages-in-your-profile-not-working/

http://wpml.org/forums/topic/hide-one-language/

http://wpml.org/forums/topic/hiding-active-language-in-menu/

http://wpml.org/forums/topic/language-selector-how-to-hide-one-language/

감사해요.

function language_selector_flags(){
    $languages = icl_get_languages('skip_missing=0');
    if(!empty($languages)){
        $filter = array();
        $filter['ar'] = array( 'he' );
        // set your other filters here

        $active_language = null;
        foreach ($languages as $l)
            if($l['active']) {
                $active_language = $l['language_code'];
                break;
            }

        $filter = $active_language && isset( $filter[$active_language] ) ? $filter[$active_language] : array();
        foreach ($languages as $l) {

                //Display whatever way you want -- I'm just displaying flags in anchors  (CSS: a {float:left; display:block;width:18px;height:12px;margin:0 2px;overflow:hidden;line-height:100px;})
                if( in_array( $l['language_code'], $filter) )
                    continue;
                if($l['active']) { $class = "active"; $url=""; } else { $class = ''; $url = 'href="'.$l['url'].'"'; }
                echo '<a '.$url.' class="flag '.$class.'"><img src="', $l['country_flag_url'], '" alt="', esc_attr( $l['language_code'] ), '" /></a>';
            }
        }
    }

편집: 제가 제대로 이해한 경우, 고객(이스라엘인 especiay)이 아랍어를 구사하는 고객에게도 서비스를 제공하는 것을 원치 않을 것입니다.그 경우는, 다음의 파일을 해석할 수 있습니다.Accept-Language헤더를 지정하고 결과에 따라 언어 선택기를 필터링합니다.

유사한 문제/문제가 있습니다.

이 웹사이트 : https://neu.member-diving.com/

스위처에는 필요 없는 언어가 있습니다.위의 코드를 사용해 봤지만, 지금까지 아무것도 바뀌지 않았습니다.

그래서 저는 클라이언트가 "독일" 페이지에 있을 때 스위처 내의 다른 독일어는 필요하지 않고 영어와 실제 독일어만 있으면 됩니다.

어디에 코드를 넣어야 합니까?

function language_selector_flags(){
    $languages = icl_get_languages('skip_missing=0');
    if(!empty($languages)){
        $filter = array();
        $filter['ar'] = array( 'he' );
        // set your other filters here

        $active_language = null;
        foreach ($languages as $l)
            if($l['active']) {
                $active_language = $l['language_code'];
                break;
            }

        $filter = $active_language && isset( $filter[$active_language] ) ? $filter[$active_language] : array();
        foreach ($languages as $l) {

                //Display whatever way you want -- I'm just displaying flags in anchors  (CSS: a {float:left; display:block;width:18px;height:12px;margin:0 2px;overflow:hidden;line-height:100px;})
                if( in_array( $l['language_code'], $filter) )
                    continue;
                if($l['active']) { $class = "active"; $url=""; } else { $class = ''; $url = 'href="'.$l['url'].'"'; }
                echo '<a '.$url.' class="flag '.$class.'"><img src="', $l['country_flag_url'], '" alt="', esc_attr( $l['language_code'] ), '" /></a>';
            }
        }
    }

언급URL : https://stackoverflow.com/questions/20346340/hide-language-wpml

반응형