我正在尝试创建一个存档照片。我的照片自定义帖子类型的php模板。我的问题是,当我查看页面时,它是归档文件。使用的是php模板,而不是存档照片。php。我只是想要存档照片。查看特定自定义帖子类型的归档页面时要使用的php。
我错过了什么?
请注意,在最后,我已将照片自定义帖子类型设置为主循环。
非常感谢您的时间和帮助。
<?php
//custom post type
add_action( \'init\', \'create_post_type\' );
function create_post_type() {
register_post_type( \'photos\',
array(
\'labels\' => array(
\'name\' => __( \'Photos\' ),
\'singular_name\' => __( \'Photo\' )
),
\'public\' => true,
\'has_archive\' => true,
\'rewrite\' => array(\'slug\' => \'photo\'),
\'menu_position\' => 5,
\'taxonomies\' => array(\'genre\'),
\'supports\' => array(\'title\', \'editor\', \'thumbnail\', \'post-formats\'),
)
);
flush_rewrite_rules( false );
//this enables post formats.
add_theme_support( \'post-formats\', array( \'image\', \'chat\', \'video\', \'gallery\' ) );
remove_post_type_support( \'post\', \'post-formats\' );
}
//hook into the init action and call create_photos_taxonomies when it fires
add_action( \'init\', \'create_photos_taxonomies\', 0 );
//create taxonomy, genres for the post type "photos"
function create_photos_taxonomies()
{
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
\'name\' => _x( \'Genres\', \'taxonomy general name\' ),
\'singular_name\' => _x( \'Genre\', \'taxonomy singular name\' ),
\'search_items\' => __( \'Search Genres\' ),
\'all_items\' => __( \'All Genres\' ),
\'parent_item\' => __( \'Parent Genre\' ),
\'parent_item_colon\' => __( \'Parent Genre:\' ),
\'edit_item\' => __( \'Edit Genre\' ),
\'update_item\' => __( \'Update Genre\' ),
\'add_new_item\' => __( \'Add New Genre\' ),
\'new_item_name\' => __( \'New Genre Name\' ),
\'menu_name\' => __( \'Genre\' ),
);
register_taxonomy(\'genre\',array(\'photos\'), array(
\'hierarchical\' => true,
\'labels\' => $labels,
\'show_ui\' => true,
\'show_admin_column\' => true,
\'query_var\' => true,
\'rewrite\' => array( \'slug\' => \'photos\' ),
));
}
function my_post_class( $classes ) {
global $post;
$terms = wp_get_object_terms( $post->ID, \'genre\' );
foreach ( $terms as $genre ) {
$classes[] = $genre->slug;
}
return $classes;
}
add_filter( \'post_class\', \'my_post_class\' );
//show posts of post type \'photos\', \'page\' on home page
add_action( \'pre_get_posts\', \'add_my_custom_post_type\' );
//make photos custom post type the default post type for the main loop
function add_my_custom_post_type( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( \'post_type\', array( \'photos\' ) );
return $query;
}
?>