是否显示自定义帖子类型的带有管理区的分类?

时间:2020-08-26 作者:M.T

我不确定这是否可行,但我希望能够在自定义帖子类型的管理区域中显示我的分类,以便WordPress用户可以对帖子进行排序,例如主题。

Picture here shows what I mean by custom post type admin area

这是我自定义帖子类型和分类的代码

register_post_type( \'courses\',
    array(
    \'labels\' => array(
      \'name\' => __( \'Courses\' ),
      \'singular_name\' => __( \'Course\' )
    ),
    \'public\' => true,
    \'has_archive\' => false,
    \'rewrite\' => array(\'slug\' => \'courses/%subject%\'),
    )
);
}

function themes_taxonomy() {
register_taxonomy(
    \'campuses\',  // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
    \'courses\',    // post type name
    array(
        \'hierarchical\' => true,
        \'label\' => \'Campuses\', // display name
        \'query_var\' => true,
        \'rewrite\' => array(
            \'slug\' => \'campus\',    // This controls the base slug that will display before each term
            \'with_front\' => false  // Don\'t display the category base before
        )
    )
);

register_taxonomy(
    \'ages\',  // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
    \'courses\',    // post type name
    array(
        \'hierarchical\' => true,
        \'label\' => \'Ages\', // display name
        \'query_var\' => true,
        \'rewrite\' => array(
            \'slug\' => \'ages\',    // This controls the base slug that will display before each term
            \'with_front\' => false  // Don\'t display the category base before
        )
    )
);

register_taxonomy(
    \'subject\',  // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
    \'courses\',    // post type name
    array(
        \'hierarchical\' => true,
        \'label\' => \'Subjects\', // display name
        \'query_var\' => true,
        \'rewrite\' => array(
            \'slug\' => \'subjects\',    // This controls the base slug that will display before each term
            \'with_front\' => false  // Don\'t display the category base before
        )
    )
);
} add_action( \'init\', \'themes_taxonomy\');

1 个回复
最合适的回答,由SO网友:Jacob Peattie 整理而成

As documented, 您可以设置show_admin_column 的参数register_taxonomy()true 为此,请执行以下操作:

\'show_admin_column\'
(bool)是否在其post类型列表屏幕上显示分类的列。默认值为false。

例如:

register_taxonomy(
    \'subject\', // The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces).
    \'courses\', // post type name
    array(
        \'label\'             => \'Subjects\', // display name
        \'show_admin_column\' => true,
        \'hierarchical\'      => true,
        \'query_var\'         => true,
        \'rewrite\'           => array(
            \'slug\'       => \'subjects\', // This controls the base slug that will display before each term
            \'with_front\' => false, // Don\'t display the category base before
        ),
    )
);

相关推荐

Dynamic CPT / Taxonomy

我在我的网站上使用了多个CPT/分类法/术语。目前,为了定制和使用好的WP模板,我做了一个taxonomy-$taxonomy.php 每个CPT的文件。但事实上,在我的模板中,只有CPT和分类词是不同的。是否存在使其动态化的解决方案?UPDATED QUESTION我所说的动态是指:只能使用taxonomy.php 模板而不是taxonomy-$taxonomy.php 模板,并具有\'post_type => \'$post_type\' 和\'taxonomy\' => \'$taxon