我在页面上使用自定义帖子类型,并对其进行管理,以使新分类法包含在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);
}
参考方案
我自己解决了。
我不得不改变:
'has_archive' => true,
至:
'has_archive' => 'branchenbuch',
php-casperjs获取内部文本 - php我正在为casperjs使用php包装器-https://github.com/alwex/php-casperjs我正在网上自动化一些重复的工作,我需要访问一个项目的innerText,但是我尚不清楚如何从casperjs浏览器访问dom。我认为在js中我会var arr = document.querySelector('label.input…
php getdate()-小时不正确 - php我在iframe中将php用于计数器。我正在使用getdate();功能。我的当地时间不是下午12:16,如果我使用getdate();从php获取现在的本地时间,小时显示为13。我从php getdate()回答的值应该不是12吗?$d1=getdate(); $hournew=$d1['hours']; echo $hournew .…
php:是否有充分的理由引用所有数组键/索引? - php我正在遍历别人的代码,他们总是避免转义其数组键。例如:$ row_rsCatalogsItems [名称]代替$ row_rsCatalogsItems ['名称']因此,我不断地对自己接触的所有事物进行微小的更改,以应对这些惰性。但是现在我想知道这样做是否有很多好处。我得到它会在默认为字符串之前检查常量(我在处理常量时会讨厌php中的行为,因为即使未定义,…
twilio'未知上下文帐户 - php我正在尝试通过Twilio和Php发送一条简单的SMS,但是出现此致命错误, 未捕获的异常“ Twilio \ Exceptions \ TwilioException”,带有消息 的“未知上下文帐户” C:\ xampp \ htdocs \ Twilio \ vendor \ twilio \ sdk \ Twilio \ Rest \ Client.p…
CakePHP将数据传递到元素 - php我的控制器中有以下代码:function index() { $posts = $this->set('posts', $this->Portfolio->find('all')); if (isset($this->params['requested'])) { retur…