一直在尝试让自定义帖子类型和分类法的嵌套工作(甚至看了一下here) 但无法让它100%工作。
事情是这样的,我创建了一个自定义的帖子类型texturas_temp 以及其中的自定义分类法categorias_texturas_temp.
我想做的是得到这个结构:
纹理温度显示全部categorias_texturas_temp
/texturas\\u temp/categorias\\u texturas\\u temp<;-显示全部texturas_temp 特别是categorias_texturas_temp term/texturas\\u temp/categorias\\u texturas\\u temp/texturas\\u temp\\u post<;-显示器single texturas_temp这与一家有/产品/类别/产品的商店几乎一样
我使用此代码创建custom taxonomy 首先:
// texturas_temp - Categorias
// =============================================================================
if ( ! function_exists( \'categorias_texturas_temp\' ) ) {
// Register Custom Taxonomy
function taxonomy_categorias_texturas_temp() {
$labels = array(
\'name\' => _x( \'Categorias de texturas_temp\', \'Taxonomy General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Categoria de texturas_temp\', \'Taxonomy Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'Categoria de texturas_temp\', \'text_domain\' ),
\'all_items\' => __( \'Todos as categorias\', \'text_domain\' ),
\'parent_item\' => __( \'Categoria Pai\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Categoria Pai:\', \'text_domain\' ),
\'new_item_name\' => __( \'Adicionar novo nome\', \'text_domain\' ),
\'add_new_item\' => __( \'Adicionar novo item\', \'text_domain\' ),
\'edit_item\' => __( \'Editar Categoria\', \'text_domain\' ),
\'update_item\' => __( \'Atualizar Categoria\', \'text_domain\' ),
\'view_item\' => __( \'Visualizar categoria\', \'text_domain\' ),
\'separate_items_with_commas\' => __( \'Separar itens com vírgulas\', \'text_domain\' ),
\'add_or_remove_items\' => __( \'Adicionar ou Remover Itens\', \'text_domain\' ),
\'choose_from_most_used\' => __( \'Escolher dos mais utilizados\', \'text_domain\' ),
\'popular_items\' => __( \'Itens Populares\', \'text_domain\' ),
\'search_items\' => __( \'Procurar Itens\', \'text_domain\' ),
\'not_found\' => __( \'Não Encontrado\', \'text_domain\' ),
\'items_list\' => __( \'Lista de Itens\', \'text_domain\' ),
\'items_list_navigation\' => __( \'Navegação Lista de Itens\', \'text_domain\' ),
);
$args = array(
\'labels\' => $labels,
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'rewrite\' => array(
\'slug\' => \'texturas_temp\', // This controls the base slug that will display before each term
),
\'show_in_nav_menus\' => true,
\'show_tagcloud\' => true,
);
register_taxonomy( \'categorias-texturas_temp\', array( \'texturas_temp\' ), $args );
}
add_action( \'init\', \'taxonomy_categorias_texturas_temp\', 0 );
}
我使用此代码创建
permalink categorias-texturas_temp:
// Modificar permalink
add_filter(\'post_link\', \'brand_permalink\', 1, 3);
add_filter(\'post_type_link\', \'brand_permalink\', 1, 3);
function brand_permalink($permalink, $post_id, $leavename) {
//con %categorias_texturas_temp% catturo il rewrite del Custom Post Type
if (strpos($permalink, \'%categorias-texturas_temp%\') === FALSE) return $permalink;
// Get post
$post = get_post($post_id);
if (!$post) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, \'categorias-texturas_temp\');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
$taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = \'no-categorias-texturas_temp\';
return str_replace(\'%categorias-texturas_temp%\', $taxonomy_slug, $permalink);
}
然后这个
my custom post type:
// texturas_temp
// =============================================================================
if ( ! function_exists(\'texturas_temp\') ) {
// Register Custom Post Type
function texturas_temp() {
$labels = array(
\'name\' => _x( \'texturas_temp\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Textura\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'texturas_temp\', \'text_domain\' ),
\'name_admin_bar\' => __( \'texturas_temp\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Textura:\', \'text_domain\' ),
\'all_items\' => __( \'Todas\', \'text_domain\' ),
\'add_new_item\' => __( \'Adicionar Nova Textura\', \'text_domain\' ),
\'add_new\' => __( \'Adicionar Nova\', \'text_domain\' ),
\'new_item\' => __( \'Adicionar Textura\', \'text_domain\' ),
\'edit_item\' => __( \'Editar Textura\', \'text_domain\' ),
\'update_item\' => __( \'Atualizar Textura\', \'text_domain\' ),
\'view_item\' => __( \'Visualizar Textura\', \'text_domain\' ),
\'search_items\' => __( \'Pesquisar Textura\', \'text_domain\' ),
\'not_found\' => __( \'Nenhuma Textura Encontrada\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'Nenhuma Textura Econtrada no Lixo\', \'text_domain\' ),
\'items_list\' => __( \'Lista de texturas_temp\', \'text_domain\' ),
\'items_list_navigation\' => __( \'Navegação Lista de texturas_temp\', \'text_domain\' ),
\'filter_items_list\' => __( \'Filtras Lista de texturas_temp\', \'text_domain\' ),
);
$args = array(
\'label\' => __( \'Textura\', \'text_domain\' ),
\'description\' => __( \'texturas_temp da Futon Company.\', \'text_domain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'revisions\', \'custom-fields\', \'page-attributes\', \'post-formats\', ),
\'taxonomies\' => array( \'texturas_temp\' ),
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
\'menu_icon\' => \'dashicons-tagcloud\',
\'show_in_admin_bar\' => true,
\'show_in_nav_menus\' => true,
\'can_export\' => true,
\'has_archive\' => true,
\'hierarchical\' => true,
\'rewrite\' => array(
\'slug\' => \'texturas_temp/%categorias-texturas_temp%\', // This controls the base slug that will display before each term
\'with_front\' => false // Don\'t display the category base before "/locations/"
),
\'query_var\' => true,
\'exclude_from_search\' => false,
\'capability_type\' => \'page\',
);
register_post_type( \'texturas_temp\', $args );
}
add_action( \'init\', \'texturas_temp\', 0 );
}
我得到的:
纹理温度404 具有archive-texturas_temp.php 模板非常适合taxonomy-categorias-texturas_temp.php 模板非常适合single-texturas_temp.php 模板所以基本上我似乎无法让父页正常工作,而且我的面包屑也没有以正确的方式显示它(跳过类别)
我做错了什么吗?这是我关心的。。。
我知道这已经被问过无数次了,见鬼,我甚至尝试了所有我找到的链接。
谁能给我点光吗?
非常感谢!
更新:我推出了插件rewrite rules inspector 内部没有错误:
texturas_temp/%categorias-texturas_temp%/?$ index.php?post_type=texturas_temp other
texturas_temp/%categorias-texturas_temp%/feed/(feed|rdf|rss|rss2|atom)/?$ index.php?post_type=texturas_temp&feed=$matches[1] other
texturas_temp/%categorias-texturas_temp%/(feed|rdf|rss|rss2|atom)/?$ index.php?post_type=texturas_temp&feed=$matches[1] other
texturas_temp/%categorias-texturas_temp%/page/([0-9]{1,})/?$ index.php?post_type=texturas_temp&paged=$matches[1] other
texturas_temp/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ index.php?categorias-texturas_temp=$matches[1]&feed=$matches[2] texturas_temp
texturas_temp/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ index.php?categorias-texturas_temp=$matches[1]&feed=$matches[2] texturas_temp
texturas_temp/([^/]+)/page/?([0-9]{1,})/?$ index.php?categorias-texturas_temp=$matches[1]&paged=$matches[2] texturas_temp
texturas_temp/([^/]+)/?$ index.php?categorias-texturas_temp=$matches[1] texturas_temp
texturas_temp/[^/]+/.+?/attachment/([^/]+)/?$ index.php?attachment=$matches[1] texturas_temp
texturas_temp/[^/]+/.+?/attachment/([^/]+)/trackback/?$ index.php?attachment=$matches[1]&tb=1 texturas_temp
texturas_temp/[^/]+/.+?/attachment/([^/]+)/feed/(feed|rdf|rss|rss2|atom)/?$ index.php?attachment=$matches[1]&feed=$matches[2] texturas_temp
texturas_temp/[^/]+/.+?/attachment/([^/]+)/(feed|rdf|rss|rss2|atom)/?$ index.php?attachment=$matches[1]&feed=$matches[2] texturas_temp
texturas_temp/[^/]+/.+?/attachment/([^/]+)/comment-page-([0-9]{1,})/?$ index.php?attachment=$matches[1]&cpage=$matches[2] texturas_temp
texturas_temp/([^/]+)/(.+?)/trackback/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&tb=1 texturas_temp
texturas_temp/([^/]+)/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&feed=$matches[3] texturas_temp
texturas_temp/([^/]+)/(.+?)/(feed|rdf|rss|rss2|atom)/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&feed=$matches[3] texturas_temp
texturas_temp/([^/]+)/(.+?)/page/?([0-9]{1,})/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&paged=$matches[3] texturas_temp
texturas_temp/([^/]+)/(.+?)/comment-page-([0-9]{1,})/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&cpage=$matches[3] texturas_temp
texturas_temp/([^/]+)/(.+?)/cornerstone-endpoint(/(.*))?/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&cornerstone-endpoint=$matches[4] texturas_temp
texturas_temp/([^/]+)/(.+?)/wc-api(/(.*))?/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&wc-api=$matches[4] texturas_temp
texturas_temp/[^/]+/.+?/([^/]+)/cornerstone-endpoint(/(.*))?/?$ index.php?attachment=$matches[1]&cornerstone-endpoint=$matches[3] texturas_temp
texturas_temp/[^/]+/.+?/attachment/([^/]+)/cornerstone-endpoint(/(.*))?/?$ index.php?attachment=$matches[1]&cornerstone-endpoint=$matches[3] texturas_temp
texturas_temp/[^/]+/.+?/([^/]+)/wc-api(/(.*))?/?$ index.php?attachment=$matches[1]&wc-api=$matches[3] texturas_temp
texturas_temp/[^/]+/.+?/attachment/([^/]+)/wc-api(/(.*))?/?$ index.php?attachment=$matches[1]&wc-api=$matches[3] texturas_temp
texturas_temp/([^/]+)/(.+?)(/[0-9]+)?/?$ index.php?categorias-texturas_temp=$matches[1]&texturas_temp=$matches[2]&page=$matches[3] texturas_temp
texturas_temp/([^/]+)/comment-page-([0-9]{1,})/?$ index.php?categorias-texturas_temp=$matches[1]&cpage=$matches[2] texturas_temp
texturas_temp/([^/]+)/cornerstone-endpoint(/(.*))?/?$ index.php?categorias-texturas_temp=$matches[1]&cornerstone-endpoint=$matches[3] texturas_temp
texturas_temp/([^/]+)/wc-api(/(.*))?/?$ index.php?categorias-texturas_temp=$matches[1]&wc-api=$matches[3] texturas_temp
SO网友:Lucas Yarid
成功了
我的问题是在自定义post类型的数组中发现了未命中代码texturas_temp
这是:
// Register Custom Post Type
function texturas_temp() {
$labels = array(
\'name\' => _x( \'texturas_temp\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Textura\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'texturas_temp\', \'text_domain\' ),
\'name_admin_bar\' => __( \'texturas_temp\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Textura:\', \'text_domain\' ),
\'all_items\' => __( \'Todas\', \'text_domain\' ),
\'add_new_item\' => __( \'Adicionar Nova Textura\', \'text_domain\' ),
\'add_new\' => __( \'Adicionar Nova\', \'text_domain\' ),
\'new_item\' => __( \'Adicionar Textura\', \'text_domain\' ),
\'edit_item\' => __( \'Editar Textura\', \'text_domain\' ),
\'update_item\' => __( \'Atualizar Textura\', \'text_domain\' ),
\'view_item\' => __( \'Visualizar Textura\', \'text_domain\' ),
\'search_items\' => __( \'Pesquisar Textura\', \'text_domain\' ),
\'not_found\' => __( \'Nenhuma Textura Encontrada\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'Nenhuma Textura Econtrada no Lixo\', \'text_domain\' ),
\'items_list\' => __( \'Lista de texturas_temp\', \'text_domain\' ),
\'items_list_navigation\' => __( \'Navegação Lista de texturas_temp\', \'text_domain\' ),
\'filter_items_list\' => __( \'Filtras Lista de texturas_temp\', \'text_domain\' ),
);
$args = array(
\'label\' => __( \'Textura\', \'text_domain\' ),
\'description\' => __( \'texturas_temp da Futon Company.\', \'text_domain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'revisions\', \'custom-fields\', \'page-attributes\', \'post-formats\', ),
\'taxonomies\' => array( \'texturas_temp\' ),
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
\'menu_icon\' => \'dashicons-tagcloud\',
\'show_in_admin_bar\' => true,
\'show_in_nav_menus\' => true,
\'can_export\' => true,
\'hierarchical\' => true,
\'rewrite\' => array(
\'slug\' => \'texturas_temp/%categorias-texturas_temp%\', // This controls the base slug that will display before each term
\'with_front\' => false // Don\'t display the category base before "/locations/"
),
\'query_var\' => \'texturas_temp-term\',
\'exclude_from_search\' => false,
\'has_archive\' => \'texturas_temp\',
\'capability_type\' => \'page\',
);
register_post_type( \'texturas_temp\', $args );
}
add_action( \'init\', \'texturas_temp\', 0 );
}
对此:
// Register Custom Post Type
function texturas_temp() {
$labels = array(
\'name\' => _x( \'texturas_temp\', \'Post Type General Name\', \'text_domain\' ),
\'singular_name\' => _x( \'Textura\', \'Post Type Singular Name\', \'text_domain\' ),
\'menu_name\' => __( \'texturas_temp\', \'text_domain\' ),
\'name_admin_bar\' => __( \'texturas_temp\', \'text_domain\' ),
\'parent_item_colon\' => __( \'Textura:\', \'text_domain\' ),
\'all_items\' => __( \'Todas\', \'text_domain\' ),
\'add_new_item\' => __( \'Adicionar Nova Textura\', \'text_domain\' ),
\'add_new\' => __( \'Adicionar Nova\', \'text_domain\' ),
\'new_item\' => __( \'Adicionar Textura\', \'text_domain\' ),
\'edit_item\' => __( \'Editar Textura\', \'text_domain\' ),
\'update_item\' => __( \'Atualizar Textura\', \'text_domain\' ),
\'view_item\' => __( \'Visualizar Textura\', \'text_domain\' ),
\'search_items\' => __( \'Pesquisar Textura\', \'text_domain\' ),
\'not_found\' => __( \'Nenhuma Textura Encontrada\', \'text_domain\' ),
\'not_found_in_trash\' => __( \'Nenhuma Textura Econtrada no Lixo\', \'text_domain\' ),
\'items_list\' => __( \'Lista de texturas_temp\', \'text_domain\' ),
\'items_list_navigation\' => __( \'Navegação Lista de texturas_temp\', \'text_domain\' ),
\'filter_items_list\' => __( \'Filtras Lista de texturas_temp\', \'text_domain\' ),
);
$args = array(
\'label\' => __( \'Textura\', \'text_domain\' ),
\'description\' => __( \'texturas_temp da Futon Company.\', \'text_domain\' ),
\'labels\' => $labels,
\'supports\' => array( \'title\', \'editor\', \'excerpt\', \'author\', \'thumbnail\', \'revisions\', \'custom-fields\', \'page-attributes\', \'post-formats\', ),
\'taxonomies\' => array( \'categorias-texturas_temp\' ),
\'hierarchical\' => true,
\'public\' => true,
\'show_ui\' => true,
\'show_in_menu\' => true,
\'menu_position\' => 5,
\'menu_icon\' => \'dashicons-tagcloud\',
\'show_in_admin_bar\' => true,
\'show_in_nav_menus\' => true,
\'can_export\' => true,
\'hierarchical\' => true,
\'rewrite\' => array(
\'slug\' => \'texturas_temp/%categorias-texturas_temp%\', // This controls the base slug that will display before each term
\'with_front\' => false // Don\'t display the category base before "/locations/"
),
\'query_var\' => \'texturas_temp-term\',
\'exclude_from_search\' => false,
\'has_archive\' => \'texturas_temp\',
\'capability_type\' => \'page\',
);
register_post_type( \'texturas_temp\', $args );
}
add_action( \'init\', \'texturas_temp\', 0 );
}
基本上,我是用自己的分类法命名我的自定义帖子类型,更改了:
\'taxonomies\' => array( \'texturas_temp\' ),
收件人:
\'taxonomies\' => array( \'categorias-texturas_temp\' ),
现在工作正常。。。