사용자 정의 게시물 유형에 태그를 추가하십시오
-
29-09-2020 - |
문제
WP 사이트에서 체리 프레임 워크를 사용하고 있습니다.그것은 '팀 구성원'을 추가하고 직원 페이지를 만드는 데 사용할 수있는 사용자 정의 게시물 유형이 함께 제공됩니다.
각 '팀 구성원'의 팀 구성원에게 태그를 추가 할 수 있으므로 본질적으로 부서 A / B / C / etc에서 일할 수 있습니다.
사용자 지정 게시물 유형은이 코드를 사용하여 theme-init.php 파일에 등록됩니다.
/* Our Team */
function my_post_type_team() {
register_post_type( 'team',
array(
'label' => theme_locals("our_team"),
'singular_label' => theme_locals("our_team"),
'_builtin' => false,
// 'exclude_from_search' => true, // Exclude from Search Results
'capability_type' => 'page',
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'menu_icon' => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
'rewrite' => array(
'slug' => 'team-view',
'with_front' => FALSE,
),
'supports' => array(
'title',
'editor',
'thumbnail',
)
)
);
}
add_action('init', 'my_post_type_team');
.
i 태그를 추가하고 싶습니다. 따라서 새 팀 구성원을 추가 할 때 주어진 관련 태그를 추가하여 부서에 할당 할 수 있습니다.현재 태그 편집기 상자가 새 / 편집 페이지 추가에 나타나지 않습니다.
그래서, 나는이 코드를 이와 같이 등록 분류를 포함하도록 위의 코드를 적용했다.
/* Our Team */
function my_post_type_team() {
register_post_type( 'team',
array(
'label' => theme_locals("our_team"),
'singular_label' => theme_locals("our_team"),
'_builtin' => false,
// 'exclude_from_search' => true, // Exclude from Search Results
'capability_type' => 'page',
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'menu_icon' => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
'rewrite' => array(
'slug' => 'team-view',
'with_front' => FALSE,
),
'supports' => array(
'title',
'editor',
'thumbnail',
)
)
);
register_taxonomy(
'team_tag',
'team',
array(
'hierarchical' => false,
'label' => theme_locals("tags"),
'singular_name' => theme_locals("tag"),
'rewrite' => true,
'query_var' => true
)
);
}
add_action('init', 'my_post_type_team');
.
그러나 Admin의 편집 페이지에 태그 상자가 표시되지 않습니다.
이와의 도움이 크게 감사 할 것입니다.
해결책
부모 / 체리 프레임 워크 테마의 theme-init.php의 일부를 덮어 쓰는 아이 테마의 Theme-init.php의 문제가 발생했습니다.
내 아이 테마의 theme-init.php에 다음 코드를 추가하여 문제를 해결했습니다.
register_taxonomy('team_tag', 'team', array(
'hierarchical' => false,
'label' => theme_locals("tags"),
'singular_name' => theme_locals("tag"),
'rewrite' => true,
'query_var' => true
)
);
. 다른 팁
이
를 사용해보십시오register_taxonomy(
'team_tag',
'team',
array(
'hierarchical' => false,
'label' => __( 'Tags', CURRENT_THEME ),
'singular_name' => __( 'Tag', CURRENT_THEME ),
'rewrite' => true,
'query_var' => true
)
);
. register_post_type( 'team',
array(
'label' => theme_locals("our_team"),
'singular_label' => theme_locals("our_team"),
'_builtin' => false,
// 'exclude_from_search' => true, // Exclude from Search Results
'capability_type' => 'page',
'public' => true,
'show_ui' => true,
'show_in_nav_menus' => false,
'menu_position' => 5,
'menu_icon' => ( version_compare( $GLOBALS['wp_version'], '3.8', '>=' ) ) ? 'dashicons-businessman' : '',
'rewrite' => array(
'slug' => 'team-view',
'with_front' => FALSE,
),
'supports' => array(
'title',
'editor',
'thumbnail',
),
'taxonomies' => array('team_tag')
)
);
.
taxonomies
매개 변수를 register_post_type
함수에 추가했는지 알 수 있습니다.
이 코드가 작동하지만 나중에 관계를 만들 수 있습니다.
add_action('init', 'add_tax_post_rel');
function add_tax_post_rel() {
register_taxonomy_for_object_type('team_tag', 'team', 11);
}
. 이 작업을 시도 할 수 있습니다
add_action( 'init', 'create_client_tax' );
function create_client_tax() {
register_taxonomy(
'client_tag', //your tags taxonomy
'client', // Your post type
array(
'hierarchical' => false,
'label' => __( 'Tags', CURRENT_THEME ),
'singular_name' => __( 'Tag', CURRENT_THEME ),
'rewrite' => true,
'query_var' => true
)
);
}
.
이 일일 수 있습니다
제휴하지 않습니다 wordpress.stackexchange