Custom post types: archive-{posttype}.php not being recognized
-
I have a custom post type, registered as ps_product. My template file single-ps_product.php works perfectly, but archive-ps_product.php is not being recognized at all–it’s defaulting to archive.php.
Here is how I’m registering the post type and the custom taxonomy, perhaps one of my array values is wrong or missing, or I’m not naming my template file correctly.
add_action( 'init', 'create_post_type' ); function create_post_type() { $labels = array( 'name' => _x('Products', 'post type general name'), 'singular_name' => _x('Product', 'post type singular name'), 'add_new' => _x('Add New', 'book'), 'add_new_item' => __('Add New Product'), 'edit_item' => __('Edit Product'), 'new_item' => __('New Product'), 'view_item' => __('View Product'), 'search_items' => __('Search Products'), 'not_found' => __('No products found'), 'not_found_in_trash' => __('No products found in Trash'), 'parent_item_colon' => '', 'menu_name' => 'Products' ); $icon = get_bloginfo ('template_directory'); $icon .= '/images/admin-ps-products-icon.png'; $productargs = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array('slug' => 'product', 'with_front' => 'false'), 'capability_type' => 'post', 'has_archive' => 'products', 'hierarchical' => false, 'menu_position' => 20, 'menu_icon' => $icon, 'taxonomies' => array('product_cat', 'post_tag'), 'supports' => array('title','editor','author','thumbnail','excerpt','comments','custom-fields', 'page-attributes') ); register_post_type( 'ps_product', $productargs); } //hook into the init action and call create_book_taxonomies when it fires add_action( 'init', 'create_product_taxonomies', 0 ); function create_product_taxonomies() { $labels = array( 'name' => _x( 'Product Categories', 'taxonomy general name' ), 'singular_name' => _x( 'Product Category', 'taxonomy singular name' ), 'search_items' => __( 'Search Product Categories' ), 'all_items' => __( 'All Product Categories' ), 'parent_item' => __( 'Parent Product Category' ), 'parent_item_colon' => __( 'Parent Product Category:' ), 'edit_item' => __( 'Edit Product Category' ), 'update_item' => __( 'Update Product Category' ), 'add_new_item' => __( 'Add New Product Category' ), 'new_item_name' => __( 'New Product Category Name' ), 'menu_name' => __( 'Product Categories' ), ); register_taxonomy('product_cat', array('ps_product'), array( 'hierarchical' => true, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'products' ), )); }
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Custom post types: archive-{posttype}.php not being recognized’ is closed to new replies.