我确实折叠了steps / solution from Jeff 它在他的设置上帮了我很多,大约90%的工作正常。但是被贴在了帖子上。它现在加载producten/%taxonomy\\u products%/而没有404错误。但当我进一步点击一篇帖子时,我再次看到404错误。
也许你能看到我做错了什么?
Custom post type and taxonomy settings \'Sorry for the dutch words\' :
add_action( \'init\', \'products_taxonomy_options\' );
function products_taxonomy_options() {
//=============== Register custom post type - PRODUCTS ================
register_post_type(\'products\',
array( \'label\' => __(\'Producten\'), // Postype
\'labels\' => array( \'name\' => __(\'Producten\'),
\'singular_name\' => __(\'Producten\'),
\'add_new\' => __(\'Product toevoegen\'),
\'add_new_item\' => __(\'Nieuw product\'),
\'edit_item\' => __(\'Wijzig product\'),
\'new_item\' => __(\'Nieuw product\'),
\'all_items\' => __(\'Alle producten\'),
\'view_item\' => __(\'Bekijk producten\'),
\'search_items\' => __(\'Zoek producten\'),
\'not_found\' => __(\'Er zijn geen producten gevonden\'),
\'not_found_in_trash\' => __(\'Geen producten gevonden in de prullenbak\')
),
\'public\' => true,
\'can_export\' => true,
\'show_ui\' => true, // UI in admin panel
\'_builtin\' => false, // It\'s a custom post type, not built in
\'_edit_link\' => \'post.php?post=%d\',
\'capability_type\' => \'post\',
//\'menu_icon\' => get_bloginfo(\'template_url\').\'/images/favicon.ico\',
\'hierarchical\' => true,
\'rewrite\' => array( "slug" => "producten"), // Permalinks
\'supports\' => array( \'title\',
\'editor\',
\'thumbnail\',
),
\'show_in_menu\' => true,
\'taxonomies\' => array(\'productcat\')
)
);
//=============== Register custom taxonomy - PRODUCTS CATEGORY ================
register_taxonomy( "productcat",
array( "products" ),
array ( "hierarchical" => true,
"label" => "Product categorieën",
\'labels\' => array( \'name\' => __(\'Product categorieën\'),
\'singular_name\' => __(\'Product categorie\'),
\'search_items\' => __(\'Categorieën zoeken\'),
\'popular_items\' => __(\'Populaire categorieën\'),
\'all_items\' => __(\'Alle categorieën\'),
\'parent_item\' => __(\'Huidige categorie\'),
\'parent_item_colon\' => __(\'Huidige categorie:\'),
\'edit_item\' => __(\'Wijzig categorie\'),
\'update_item\' => __(\'Update categorie\'),
\'add_new_item\' => __(\'Nieuwe categorie toevoegen\'),
\'new_item_name\' => __(\'Nieuwe categorie\')
),
\'show_ui\' => false,
\'query_var\' => true,
\'_builtin\' => false,
\'paged\' => true,
\'rewrite\' => array( \'hierarchical\' => true,
\'slug\' =>\'products\',
\'with_front\' => false
),
)
);
}
Jeff\'s settings:
add_filter(\'rewrite_rules_array\', \'mmp_rewrite_rules\');
function mmp_rewrite_rules($rules) {
$newRules = array();
$newRules[\'producten/(.+)/(.+)/(.+)/(.+)/?$\'] = \'index.php?products=$matches[4]\'; // my custom structure will also have the post name as the 5th uri segment
$newRules[\'producten/(.+)/?$\'] = \'index.php?productcat=$matches[1]\';
return array_merge($newRules, $rules);
}
function filter_post_type_link($link, $post)
{
if ($post->post_type != \'products\')
return $link;
if ($cats = get_the_terms($post->ID, \'productcat\'))
{
$link = str_replace(\'%taxonomy_products%\', get_taxonomy_parents(array_pop($cats)->term_id, \'productcat\', false, \'/\', true), $link); // see custom function defined below
}
return $link;
}
add_filter(\'post_type_link\', \'filter_post_type_link\', 10, 2);
// my own function to do what get_category_parents does for other taxonomies
function get_taxonomy_parents($id, $taxonomy, $link = false, $separator = \'/\', $nicename = false, $visited = array()) {
$chain = \'\';
$parent = &get_term($id, $taxonomy);
if (is_wp_error($parent)) {
return $parent;
}
if ($nicename)
$name = $parent -> slug;
else
$name = $parent -> name;
if ($parent -> parent && ($parent -> parent != $parent -> term_id) && !in_array($parent -> parent, $visited)) {
$visited[] = $parent -> parent;
$chain .= get_taxonomy_parents($parent -> parent, $taxonomy, $link, $separator, $nicename, $visited);
}
if ($link) {
// nothing, can\'t get this working :(
} else
$chain .= $name . $separator;
return $chain;
}
Permalink settings:
/producten/%taxonomy_products%/%postname%/
Working with the Taxonomic SEO Permalink plugin
谢谢