WPML

수동으로 사용자 정의 글 유형을 등록할 때 WordPress에서 별도의 아카이브 슬러그를 설정할 수 있습니다. 이 구성 방식에 따라 슬러그가 보조 언어로 번역될지 여부가 결정됩니다.

사용자 정의 글 유형을 수동으로 등록할 때 has_archive 함수를 사용하여 별도의 아카이브 슬러그를 설정할 수 있습니다.

WPML을 사용하면 has_archive에 문자열을 설정할 수 있습니다. 하지만 문자열 값이 rewrite['slug'], 이외의 값으로 설정되거나 사용자 정의 글 유형 이름 슬러그가 설정되지 않은 경우 아카이브 슬러그를 번역할 수 없습니다.

번역 가능한 슬러그 설정


이 코드 예시에서는 'has_archive' => true 값을 설정합니다. book 슬러그가 스페인어 libro로 번역되었다고 가정할 때 아카이브 링크는 다음과 같습니다.

  • 영어(기본 언어): http://mydomain.tld/book/

  • 스페인어(보조 언어): http://mydomain.tld/es/libro/

	 	 
add_action( 'init', 'create_post_type' );	 	 
function create_post_type() {	 	 
   register_post_type( 'book',	 	 
      array(	 	 
         'labels' => array(	 	 
            'name' => __( 'Books', 'textdomain' ),	 	 
            'singular_name' => __( 'Book', 'textdomain' )	 	 
         ),	 	 
         'public' => true,	 	 
         'has_archive' => true,	 	 
         'publicly_queryable' => true,	 	 
         'exclude_from_search' => false,	 	 
         'show_ui' => true,	 	 
         'show_in_menu' => true,	 	 
         'query_var' => true,	 	 
         'rewrite' => array('slug' => 'book'),	 	 
         'supports' => array('title','editor', 'custom-fields','thumbnail')	 	 
      )	 	 
   );	 	 
}	 	 

기본 언어와 보조 언어에 동일한 슬러그 설정

이 코드 예시에서는 'has_archive' => 'my-books' 매개변수에 특정 문자열을 설정합니다. 이제 아카이브 링크는 다음과 같습니다.
  • 영어(기본 언어): http://mydomain.tld/my-books/
  • 스페인어(보조 언어): http://mydomain.tld/es/my-books/
	 	 
add_action( 'init', 'create_post_type' );	 	 
function create_post_type() {	 	 
   register_post_type( 'book',	 	 
      array(	 	 
         'labels' => array(	 	 
            'name' => __( 'Books', 'textdomain' ),	 	 
            'singular_name' => __( 'Book', 'textdomain' )	 	 
         ),	 	 
         'public' => true,	 	 
         'has_archive' => 'my-books', // Do not use the gettext functions for this parameter	 	 
         'publicly_queryable' => true,	 	 
         'exclude_from_search' => false,	 	 
         'show_ui' => true,	 	 
         'show_in_menu' => true,	 	 
         'query_var' => true,	 	 
         'rewrite' => array('slug' => 'book'),	 	 
         'supports' => array('title','editor', 'custom-fields','thumbnail')	 	 
      )	 	 
   );	 	 
}	 	 

사용자 지정 가능한 슬러그 문제 해결


일부 테마와 플러그인은 사이트 관리자가 사용자 정의 글 유형 및 사용자 정의 분류체계에 대한 사용자 지정 슬러그를 설정할 수 있도록 지원합니다.

번역된 사용자 지정 슬러그에서 404 오류가 반환되는 경우 다음 사항을 확인하세요.


  • 사용자 정의 유형은 언어별, 프런트엔드, 백엔드, AJAX, 하트비트 등 모든 요청에서 항상 동일한 슬러그로 등록되어야 합니다. 따라서 'rewrite' => [ 'slug' => $my_custom_slug ],$my_custom_slug 값은 옵션(또는 사용자 지정 설정)에서 가져오더라도 요청에 따라 변경되지 않아야 합니다.

  • WPML은 (사용자 정의 유형이 등록될 때) 사용자 지정 슬러그 번역만 지원하며 사용자 지정 고유주소 구조는 지원하지 않습니다.

  • 사용자 지정 슬러그가 옵션으로 저장된 경우 wpml-config.xml 파일에 admin-texts 항목으로 등록되지 않아야 합니다.

  • 사용자 지정 슬러그의 값을 업데이트한 후에는 테마/플러그인에서도 (flush_rewrite_rules(); 함수를 호출하여) 재작성 규칙을 플러시해야 합니다.

작성자: Amir · 마지막 업데이트: 2024년 5월 30일