【发布时间】:2016-11-29 02:42:29
【问题描述】:
我想在我的网站上添加一个带有照片的部分。照片应在分类法和 custom_post_types 的帮助下进行分组。链接应该是这样的
-
mysite.com/photography=> 分类模板 -
mysite.com/photography/underwater=> 分类术语模板
我在 functions.php 中创建了分类和 custom_post_type,这是代码。
function photos_custom_post_type() {
$labels = array(
'name' => __( 'Photos' ),
'singular_name' => __( 'Photo'),
'menu_name' => __( 'Photos'),
'parent_item_colon' => __( 'Parent Photo'),
'all_items' => __( 'All Photos'),
'view_item' => __( 'View Photo'),
'add_new_item' => __( 'Add New Photo'),
'add_new' => __( 'Add New'),
'edit_item' => __( 'Edit Photo'),
'update_item' => __( 'Update Photo'),
'search_items' => __( 'Search Photo'),
'not_found' => __( 'Not Found'),
'not_found_in_trash' => __( 'Not found in Trash')
);
$args = array(
'label' => __( 'photos'),
'description' => __( 'Best Photos'),
'labels' => $labels,
'supports' => array( 'title','thumbnail',),
'public' => true,
'hierarchical' => false,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'has_archive' => true,
'can_export' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'taxonomies' => array('post_tag')
);
register_post_type( 'photos', $args );
}
add_action( 'init', 'photos_custom_post_type', 0 );
// creating Taxonomy for Custom Post Type
add_action( 'init', 'photos_custom_taxonomy', 0 );
function photos_custom_taxonomy() {
$labels = array(
'name' => _x( 'Photos Category', 'taxonomy general name' ),
'singular_name' => _x( 'Photos Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Photos Category' ),
'all_items' => __( 'All Photos Category' ),
'parent_item' => __( 'Parent Photos Category' ),
'parent_item_colon' => __( 'Parent Photos Category:' ),
'edit_item' => __( 'Edit Photos Category' ),
'update_item' => __( 'Update Photos Category' ),
'add_new_item' => __( 'Add New Photos Category' ),
'new_item_name' => __( 'New Photos Category Name' ),
'menu_name' => __( 'Photos Category' ),
);
register_taxonomy('photos_cat',array('photos'), array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'rewrite' => array('slug' => 'photography', 'with_front' => false)
));
}
我也创造了
-
taxonomy-post_cat-underwater.php=> 这行得通 -
taxonomy-post_cat.php=> 这不是
当我转到mysite.com/photography/underwater => 一切正常,但是当我转到mysite.com/photography => 我得到 404 错误..
请帮助我了解发生了什么问题。
【问题讨论】:
-
在 wp-config.php 中设置 WP_DEBUG = true 。错误信息是什么?
-
@elicohenator 没有错误,只有 404 页
标签: php wordpress custom-post-type taxonomy