我在页面上使用自定义帖子类型并管理新分类包含在URL中。一切都运作良好,但是当我访问example.com/branchenbuch/时,我得到了404。
example.com/branchenbuch/ - >失败 example.com/branchenbuch/customtaxonomy - >作品 example.com/branchenbuch/customtaxonomy/post - >作品
有人知道为什么吗?
代码如下:
if ( ! function_exists('register_custom_post_types') ) {
// Register Custom Post Type Kollektion
function register_custom_post_types() {
add_rewrite_tag('%kategorie%','(.+)');
$labels = array(
'name' => _x( 'Branchenbuch', 'Post Type General Name', 'genesis' ),
'singular_name' => _x( 'Branchenbuch', 'Post Type Singular Name', 'genesis' ),
'menu_name' => __( 'Branchenbuch', 'genesis' ),
'name_admin_bar' => __( 'Branchenbuch', 'genesis' ),
'parent_item_colon' => __( 'Parent Item:', 'genesis' ),
'all_items' => __( 'Alle Einträge', 'genesis' ),
'add_new_item' => __( 'Neuen Eintrag hinzufügen', 'genesis' ),
'add_new' => __( 'Neu hinzufügen', 'genesis' ),
'new_item' => __( 'Neu', 'genesis' ),
'edit_item' => __( 'Editieren', 'genesis' ),
'update_item' => __( 'Aktualisieren', 'genesis' ),
'view_item' => __( 'Ansehen', 'genesis' ),
'search_items' => __( 'Suche', 'genesis' ),
'not_found' => __( 'Nicht gefunden', 'genesis' ),
'not_found_in_trash' => __( 'Nicht im Papierkorb gefunden', 'genesis' ),
'items_list' => __( 'Liste', 'genesis' ),
'items_list_navigation' => __( 'Liste Navigation', 'genesis' ),
'filter_items_list' => __( 'Filter', 'genesis' ),
);
$args = array(
'label' => __( 'Branchenbuch', 'genesis' ),
'description' => __( 'Branchenbuch', 'genesis' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', ),
'taxonomies' => array( 'branchenbuch-kategorie' ),
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
'rewrite' => array('slug' => 'branchenbuch/%kategorie%','with_front' => false),
);
register_post_type( 'branchenbuch', $args );
}//function
add_action( 'init', 'register_custom_post_types');
}
// register two taxonomies to go with the post type
function custom_register_taxonomy() {
// set up labels
$labels = array(
'name' => 'Branchenbuch Kategorien',
'singular_name' => 'Branchenbuch Kategorie',
'search_items' => 'Suche',
'all_items' => 'Alle Kategorien',
'edit_item' => 'Editieren',
'update_item' => 'Aktualisieren',
'add_new_item' => 'Neu hinzufügen',
'new_item_name' => 'Neu hinzufügen',
'menu_name' => 'Kategorien'
);
// register taxonomy
register_taxonomy( 'branchenbuch-kategorie', 'branchenbuch', array(
'hierarchical' => true,
'labels' => $labels,
'query_var' => true,
'show_admin_column' => true,
'rewrite' => array(
'slug' => 'branchenbuch-kategorie', // This controls the base slug that will display before each term
),
) );
}
add_action( 'init', 'custom_register_taxonomy' );
/* Filter modifies the permaling */
add_filter('post_link', 'custom_category_permalink', 1, 3);
add_filter('post_type_link', 'custom_category_permalink', 1, 3);
function custom_category_permalink($permalink, $post_id, $leavename) {
if (strpos($permalink, '%kategorie%') === FALSE) return $permalink;
// Get post
$post = get_post($post_id);
if (!$post) return $permalink;
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'branchenbuch-kategorie');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0]))
$taxonomy_slug = $terms[0]->slug;
else $taxonomy_slug = 'sonstiges';
return str_replace('%kategorie%', $taxonomy_slug, $permalink);
}
答案 0 :(得分:3)
我自己解决了。
我不得不改变:
'has_archive' => true,
为:
'has_archive' => 'branchenbuch',
答案 1 :(得分:0)
这将重写htaccess文件,然后重写应该有效。
我希望这会节省你的时间。