我已经使用自定义帖子类型有一段时间了,但昨天我第一次尝试使用自定义分类法来与它们配对。
以下是我的“公司”分类法:
function create_company_taxonomy() {
$labels = array(
\'name\' => _x( \'Companies\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Company\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Companies\' ),
\'all_items\' => __( \'All Companies\' ),
\'parent_item\' => __( \'Parent Company\' ),
\'parent_item_colon\' => __( \'Parent Company:\' ),
\'edit_item\' => __( \'Edit Companies\' ),
\'update_item\' => __( \'Update Companies\' ),
\'add_new_item\' => __( \'Add New Company\' ),
\'new_item_name\' => __( \'New Company Name\' ),
\'menu_name\' => __( \'Company\' ),
);
$args = array(
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'company\' ),
\'public\' => true,
\'hierarchical\' => true,
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'query_var\' => true,
\'publicly_queryable\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => true,
\'has_archive\' => true
);
register_taxonomy( \'company\', array( \'brochures\',\'business-cards\',\'post\',\'websites\' ), $args );
}
add_action( \'init\', \'create_company_taxonomy\', 0 );
正如你所见,我正在尝试将其用于“帖子”以及三种自定义帖子类型——“宣传册”、“名片”、“网站”
当我创建一家分类公司时。php模板(基于archive.php)并为这些post\\u类型中的每一个类型提供分类法中的术语,只有post才会显示在页面上。我根本无法显示自定义帖子类型。
我需要自定义查询吗?如有任何见解,将不胜感激。
编辑:这也是我的register\\u post\\u类型之一
add_action( \'init\', \'create_custom_post_types\' );
function create_custom_post_types() {
$labels = array(
\'name\' => __( \'Websites\' ),
\'singular_name\' => __( \'Website\' )
);
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\' => \'websites\'),
\'taxonomies\' => array( \'category\',\'company\',\'post_tag\' ),
\'supports\' => array( \'title\', \'editor\', \'thumbnail\' , \'custom-fields\', \'excerpt\' ),
\'exclude_from_search\' => true
);
register_post_type( \'websites\', $args);
}