custom post type category page

I can't seem to get archive page or category page to work correctly.I am following and it still defaults to archive

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

I am following

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 ) );
}

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

I am following http://codex.wordpress/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 ) );
}
Share Improve this question edited Feb 8, 2013 at 16:08 Lukasz asked Feb 7, 2013 at 20:56 LukaszLukasz 481 gold badge2 silver badges7 bronze badges 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
Add a comment  | 

2 Answers 2

Reset to default 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.

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!

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742267034a4411993.html

相关推荐

  • custom post type category page

    I can't seem to get archive page or category page to work correctly.I am following and it still defaults to archive

    1天前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信