2

I can't seem to get archive page or category page to work correctly.

I am following http://codex.wordpress.org/Template_Hierarchy#Category_display

and it still defaults to archive.php ( i think, according to chart ) even though I have named it category-business.php

here is my code:

/******************
//  Business
******************/

function my_custom_post_business() {
  $labels = array(
        'name'               => _x( 'business', 'post type general name' ),
        'singular_name'      => _x( 'business', 'post type singular name' ),
        'add_new'            => _x( 'Add New', 'book' ),
        'add_new_item'       => __( 'Add New business' ),
        'edit_item'          => __( 'Edit business' ),
        'new_item'           => __( 'New business' ),
        'all_items'          => __( 'All business' ),
        'view_item'          => __( 'View business' ),
        'search_items'       => __( 'Search business' ),
        'not_found'          => __( 'No business found' ),
        'not_found_in_trash' => __( 'No business found in the Trash' ), 
        'parent_item_colon'  => '',
        'menu_name'          => 'business'
    );
    $args = array(
        'labels'        => $labels,
        'description'   => 'Holds our business and business specific data',
        'public'        => true,
        'hierarchical'      => true,
        'show_ui'           => true,
        'show_in_nav_menus' => true,
        'menu_position' => 5,
        'supports'      => array( 'title', 'editor', 'thumbnail', 'excerpt', 'comments' ),
        'has_archive'   => true,

        //'taxonomies' => array('category'),
    );
    register_post_type( 'business', $args );

}
add_action( 'init', 'my_custom_post_business' );



/** add categories for custom post type */
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
    register_taxonomy( 'mycategories', 'business', array( 'hierarchical' => true, 'label' => 'Business Categories', 'query_var' => true, 'rewrite' => true ) );
}
2
  • Hi, please embed all relevant code in the Question itself, you are free to edit it whenever needed.
    – brasofilo
    Commented Feb 7, 2013 at 21:19
  • done. thank you for bringing this to my attention.
    – Lukasz
    Commented Feb 8, 2013 at 16:08

2 Answers 2

5

Since you are using a custom taxonomy and not the native post categories you need to name your file taxonomy-{taxonomy}.php and in your case it would be taxonomy-mycategories.php

Take a look at the section of the template hierarchy to display custom taxonomy archives.

1
  • After creating taxonomy-{taxonomy}.php don't forget to go to the permalinks section and click "save" Commented Aug 30, 2018 at 20:00
1

Just a quick addition to this if anyone arrived here like I did when trying to create custom taxonomy archives.

If you ALREADY have taxonomies created then adjust your CPT code to allow it to have an archive, you will need to delete these taxonomies and clear your cache. New taxonomies will work but for some reason, older taxes create 404's (even after clearing permalinks!).

Hope that helps!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.