意外 Archive.php 显示帖子而不是存档-{自定义 Post 类型}
Unexpexted Archive.php show posts instead of archive-{Custom Post Type}
我已经创建了我的 Post 类型,但我不知道我做错了什么 archive.php 显示所有 post 而不是存档-gallery.php。这是代码。
自定义-post-types.php
/******* *******/
// Custom Post Type - gallery
function register_post_gallery() {
$labels = array(
'name' => __( 'gallery', '_tk' ),
'singular_name' => __( 'gallery', '_tk' ),
'add_new' => __( 'Dodaj nową', '_tk' ),
'add_new_item' => __( 'Dodaj nową galerię', '_tk' ),
'edit_item' => __( 'Edytuj', '_tk' ),
'new_item' => __( 'Nowa', '_tk' ),
'all_items' => __( 'Wszystkie', '_tk' ),
'view_item' => __( 'Zobacz', '_tk' ),
'search_items' => __( 'Szukaj', '_tk' ),
'not_found' => __( 'Nie zneleziono żadnej', '_tk' ),
'not_found_in_trash' => __( 'Nie zneleziono żadnej w koszu', '_tk' ),
'parent_item_colon' => '',
'menu_name' => __( 'Galeria', '_tk' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'supports' => array( 'title', 'page-attributes', 'revisions', 'thumbnail' ),
'taxonomies' => array( 'gallery_category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'rewrite' => array('slug' => 'gallery','with_front' => false),
'menu_position' => 6,
'menu_icon' => 'dashicons-admin-multisite'
);
register_post_type( 'galllery', $args );
}
add_action( 'init', 'register_post_gallery' );
/* gallery taxonomies */
function add_gallery_category() {
$labels = array(
'name' => __( 'Kategorie galerii', '_tk' ),
'singular_name' => __( 'Kategoria galerii', '_tk' ),
'search_items' => __( 'Szukaj kategorii', '_tk' ),
'all_items' => __( 'Wszystkie kategorie', '_tk' ),
'parent_item' => __( 'Kategoria nadrzędna', '_tk' ),
'parent_item_colon' => __( 'Kategoria nadrzędna:', '_tk' ),
'edit_item' => __( 'Edytuj kategorię', '_tk' ),
'update_item' => __( 'Aktualizuj kategorię', '_tk' ),
'add_new_item' => __( 'Dodaj nową kategorię', '_tk' ),
'new_item_name' => __( 'Nowa kategoria', '_tk' ),
'menu_name' => __( 'Kategorie galerii', '_tk' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'kategorie-galerii' )
);
register_taxonomy( 'gallery_category', 'gallery', $args );
}
add_action( 'init', 'add_gallery_category', 0 );
这是我在主题中的文件:
什么文件插件告诉我页面是由archive.php
显示的
你能帮我解决这个问题吗?我试图注意到问题出在哪里,但没有结果。
注册时您的图库中有错字:
register_post_type( 'galllery', $args );
将其更改为 gallery
而不是 galllery
。
我已经创建了我的 Post 类型,但我不知道我做错了什么 archive.php 显示所有 post 而不是存档-gallery.php。这是代码。
自定义-post-types.php
/******* *******/
// Custom Post Type - gallery
function register_post_gallery() {
$labels = array(
'name' => __( 'gallery', '_tk' ),
'singular_name' => __( 'gallery', '_tk' ),
'add_new' => __( 'Dodaj nową', '_tk' ),
'add_new_item' => __( 'Dodaj nową galerię', '_tk' ),
'edit_item' => __( 'Edytuj', '_tk' ),
'new_item' => __( 'Nowa', '_tk' ),
'all_items' => __( 'Wszystkie', '_tk' ),
'view_item' => __( 'Zobacz', '_tk' ),
'search_items' => __( 'Szukaj', '_tk' ),
'not_found' => __( 'Nie zneleziono żadnej', '_tk' ),
'not_found_in_trash' => __( 'Nie zneleziono żadnej w koszu', '_tk' ),
'parent_item_colon' => '',
'menu_name' => __( 'Galeria', '_tk' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'supports' => array( 'title', 'page-attributes', 'revisions', 'thumbnail' ),
'taxonomies' => array( 'gallery_category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'rewrite' => array('slug' => 'gallery','with_front' => false),
'menu_position' => 6,
'menu_icon' => 'dashicons-admin-multisite'
);
register_post_type( 'galllery', $args );
}
add_action( 'init', 'register_post_gallery' );
/* gallery taxonomies */
function add_gallery_category() {
$labels = array(
'name' => __( 'Kategorie galerii', '_tk' ),
'singular_name' => __( 'Kategoria galerii', '_tk' ),
'search_items' => __( 'Szukaj kategorii', '_tk' ),
'all_items' => __( 'Wszystkie kategorie', '_tk' ),
'parent_item' => __( 'Kategoria nadrzędna', '_tk' ),
'parent_item_colon' => __( 'Kategoria nadrzędna:', '_tk' ),
'edit_item' => __( 'Edytuj kategorię', '_tk' ),
'update_item' => __( 'Aktualizuj kategorię', '_tk' ),
'add_new_item' => __( 'Dodaj nową kategorię', '_tk' ),
'new_item_name' => __( 'Nowa kategoria', '_tk' ),
'menu_name' => __( 'Kategorie galerii', '_tk' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'kategorie-galerii' )
);
register_taxonomy( 'gallery_category', 'gallery', $args );
}
add_action( 'init', 'add_gallery_category', 0 );
这是我在主题中的文件:
什么文件插件告诉我页面是由archive.php
显示的你能帮我解决这个问题吗?我试图注意到问题出在哪里,但没有结果。
注册时您的图库中有错字:
register_post_type( 'galllery', $args );
将其更改为 gallery
而不是 galllery
。