맞춤 게시물 유형의 관리 항목에 카테고리를 추가 하시겠습니까?


13

기사라는 사용자 정의 게시물 유형을 작성했으며 관리자 요약 화면에 제공된 정보가 희박합니다. 튜토리얼 의 http://codex.wordpress.org/Plugin_API/Action_Reference/manage_posts_custom_column 을 사용하여 추천 이미지 게시물 썸네일 이미지를 추가 할 수있었습니다 .

그러나이 게시물이 관리자 페이지에서 할당 한 범주 및 하위 범주에 대한 개요를 얻고 싶습니다. 즉 해당 부분에 열을 추가합니까?

다음은 맞춤 게시물 유형 코드에서 분류법을 등록하는 데 사용한 코드입니다.


답변:


18

register_taxonomy의 함수라는 파라미터 갖는 show_admin_column컬럼을 추가 처리 할 것을. 당신은 그것을 시도 했습니까?

예 :

register_taxonomy(
    'my_tax, 
    'post_type', 
    array(
        'label'             => 'My Taxonomy',
        'show_admin_column' => true,
        )
);

1
코드를 추가하고 코드를 사용하여 쿼리에 어떻게 응답하는지 설명하십시오. OP에 무언가를 묻고 싶다면 주석을 사용하십시오.
cybmeta

6

일부 검색 후 manage_edit-${post_type}_columns필터와 manage_${post_type}_posts_custom_column작업을 사용하여 솔루션을 찾았습니다 .

필터를 사용하여 열을 만든 다음 작업으로 열을 채 웁니다. 이 링크 http://justintadlock.com/archives/2011/06/27/custom-columns-for-custom-post-types 의 아이디어를 사용하여 추가 열을 쉽게 추가하고 채울 수 있다고 가정합니다.

add_filter('manage_edit-article_columns', 'my_columns');
function my_columns($columns) {
    $columns['article_category'] = 'Category';
return $columns;
}

add_action( 'manage_article_posts_custom_column', 'my_manage_article_columns', 10, 2 );

function my_manage_article_columns( $column, $post_id ) {
global $post;

switch( $column ) {

    /* If displaying the 'article_category' column. */
    case 'article_category' :

        /* Get the genres for the post. */
        $terms = get_the_terms( $post_id, 'article_category' );

        /* If terms were found. */
        if ( !empty( $terms ) ) {

            $out = array();

            /* Loop through each term, linking to the 'edit posts' page for the specific term. */
            foreach ( $terms as $term ) {
                $out[] = sprintf( '<a href="%s">%s</a>',
                    esc_url( add_query_arg( array( 'post_type' => $post->post_type, 'article_category' => $term->slug ), 'edit.php' ) ),
                    esc_html( sanitize_term_field( 'name', $term->name, $term->term_id, 'article_category', 'display' ) )
                );
            }

            /* Join the terms, separating them with a comma. */
            echo join( ', ', $out );
        }

        /* If no terms were found, output a default message. */
        else {
            _e( 'No Articles' );
        }

        break;

    /* Just break out of the switch statement for everything else. */
    default :
        break;
}
}
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.