我有一个名为“properties”的自定义帖子类型和两个名为“type”(办公空间、零售空间等)和“location”(纽约、芝加哥等)的自定义分类法。
我已经创建了“archive properties.php”,当我访问“mysite.com/properties”时,它的工作非常出色我有“single properties.php”,当我访问“mysite.com/properties/my single post”时,它非常有用
我创建了一些动态类型和位置导航菜单,其中填充了分类法中所有可用的“类型”和“位置”。我有一个“taxonomy properties.php”模板文件。不幸的是,“mysite.com/office space”和“mysite.com/properties/office space”都会产生404。任何城市都一样。
我已经尝试过Permalinks的技巧,但没有成功。我已经看了关于这个话题的其他问题,但没有找到答案。
我需要创建什么文件才能使其工作,它需要放在哪里?我是不是期望太高了?Wordpress真的不是这样工作的吗?如果没有,为我的自定义分类法显示“归档”页面的最佳方式是什么?
难点:“类型”分类法不太可能改变,因为客户端只处理办公空间和零售空间。但是城市总是被添加到“位置”分类中,所以我不能只为每个城市创建一个模板文件。
更新:添加我用来创建自定义帖子类型和分类的代码。
function create_post_type_properties() {
$labels = array(
\'name\' => __(\'Properties\', \'properties\'),
\'singular_name\' => __(\'Property\', \'properties\'),
\'add_new\' => __(\'Add New\', \'properties\'),
\'add_new_item\' => __(\'Add New Property\', \'properties\'),
\'edit\' => __(\'Edit\', \'properties\'),
\'edit_item\' => __(\'Edit Property\', \'properties\'),
\'new_item\' => __(\'New Property\', \'properties\'),
\'view\' => __(\'View Property\', \'properties\'),
\'view_item\' => __(\'View Property\', \'properties\'),
\'search_items\' => __(\'Search Properties\', \'properties\'),
\'not_found\' => __(\'No Properties found\', \'properties\'),
\'not_found_in_trash\' => __(\'No Properties found in Trash\', \'properties\'),
\'parent_item_colon\' => \'\',
\'menu_name\' => \'Properties\'
);
$args = array(
\'labels\' => $labels,
\'description\' => \'Properties & property specific data\',
\'public\' => true,
\'menu_position\' => 5,
\'supports\' => array(\'title\', \'editor\', \'thumbnail\', \'custom-fields\'),
\'taxonomies\' => array(\'\'),
\'has_archive\' => true,
\'can_export\' => true,
\'menu_icon\' => plugins_url( \'image.png\', __FILE__ ),
);
register_post_type( \'properties\', $args );
}
/* Create custom taxonomy (type) for properties */
function property_type_taxonomy() {
$labels = array(
\'name\' => _x( \'Property Types\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Property Type\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Property Types\' ),
\'all_items\' => __( \'All Property Types\' ),
\'parent_item\' => __( \'Parent Property Type\' ),
\'parent_item_colon\' => __( \'Parent Property Type:\' ),
\'edit_item\' => __( \'Edit Property Type\' ),
\'update_item\' => __( \'Update Property Type\' ),
\'add_new_item\' => __( \'Add New Property Type\' ),
\'new_item_name\' => __( \'New Property Type\' ),
\'menu_name\' => __( \'Property Types\' ),
);
$args = array(
\'labels\' => $labels,
\'show_ui\' => true,
\'show_tagcloud\' => false,
\'hierarchical\' => true
);
register_taxonomy( \'property_type\', \'properties\', $args );
}
/* Create custom taxonomy (location) for properties */
function property_location_taxonomy() {
$labels = array(
\'name\' => _x( \'Property Locations\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Property Location\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Property Locations\' ),
\'all_items\' => __( \'All Property Locations\' ),
\'parent_item\' => __( \'Parent Property Location\' ),
\'parent_item_colon\' => __( \'Parent Property Location:\' ),
\'edit_item\' => __( \'Edit Property Location\' ),
\'update_item\' => __( \'Update Property Location\' ),
\'add_new_item\' => __( \'Add New Property Location\' ),
\'new_item_name\' => __( \'New Property Location\' ),
\'menu_name\' => __( \'Property Locations\' ),
);
$args = array(
\'labels\' => $labels,
\'show_ui\' => true,
\'show_tagcloud\' => false,
\'hierarchical\' => true
);
register_taxonomy( \'property_location\', \'properties\', $args );
}