0
votes

I would like to create a unique design category for my custom post type. Here I get it design for main post type but the same design not applying for the category pages it takes to the default category page.

My Custom Post Type name resources for that I create a separate designed template archive-resources.php, so it's working fine but for custom post category page I tried in many ways but still I won't get the result (created separate Taxonomy like category-resources.php) but still not works.

Once I added a category for my custom post type resources as hotels for the hotels category I get default post category design but I won't what that. I like the same design want custom post type resources.

This is my custom post type functions.php


function custom_resource_type() {

    $labels = array(
        'name'                => _x( 'Resources', 'Post Type General Name', 'gucherry-blog' ),
        'singular_name'       => _x( 'Resource', 'Post Type Singular Name', 'gucherry-blog' ),
        'menu_name'           => __( 'Resources', 'gucherry-blog' ),
        'parent_item_colon'   => __( 'Parent Resource', 'gucherry-blog' ),
        'all_items'           => __( 'All Resources', 'gucherry-blog' ),
        'view_item'           => __( 'View Resource', 'gucherry-blog' ),
        'add_new_item'        => __( 'Add New Resource', 'gucherry-blog' ),
        'add_new'             => __( 'Add Resource', 'gucherry-blog' ),
        'edit_item'           => __( 'Edit Resource', 'gucherry-blog' ),
        'update_item'         => __( 'Update Resource', 'gucherry-blog' ),
        'search_items'        => __( 'Search Resource', 'gucherry-blog' ),
        'not_found'           => __( 'Not Found', 'gucherry-blog' ),
        'not_found_in_trash'  => __( 'Not found in Trash', 'gucherry-blog' ),
    );

    $args = array(
        'label'               => __( 'resources', 'gucherry-blog' ),
        'description'         => __( 'Resource for software products and online', 'gucherry-blog' ),
        'labels'              => $labels,
        'supports'            => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'revisions', 'custom-fields', ),
        'taxonomies'          => array( '' ),
        'hierarchical'        => false,
        'public'              => true,
        'show_ui'             => true,
        'show_in_menu'        => true,
        'show_in_nav_menus'   => true,
        'show_in_admin_bar'   => true,
        'menu_position'       => 5,
        'can_export'          => true,
        'has_archive'         => true,
        'exclude_from_search' => false,
        'publicly_queryable'  => true,
        'menu_icon'           => 'dashicons-admin-site-alt2',
        'capability_type'     => 'page',
    );

    register_post_type( 'resources', $args );

}

add_action( 'init', 'custom_resource_type', 0 );

function resource_categories_taxonomy() {

  $resource_cats = array(
    'name' => _x( 'Resource Categories', 'taxonomy general name', 'gucherry-blog' ),
    'singular_name' => _x( 'Resource Category', 'taxonomy singular name', 'gucherry-blog' ),
    'search_items' =>  __( 'Search Resource Categories', 'gucherry-blog' ),
    'all_items' => __( 'All Resource', 'gucherry-blog' ),
    'parent_item' => __( 'Parent Resource', 'gucherry-blog' ),
    'parent_item_colon' => __( 'Parent Resource:', 'gucherry-blog' ),
    'edit_item' => __( 'Edit Resource', 'gucherry-blog' ), 
    'update_item' => __( 'Update Resource', 'gucherry-blog' ),
    'add_new_item' => __( 'Add New Resource', 'gucherry-blog' ),
    'new_item_name' => __( 'New Resource', 'gucherry-blog' ),
    'menu_name' => __( 'Resource Categories', 'gucherry-blog' ),
  );    

  register_taxonomy('resource_categories',array('resources'), array(
    'hierarchical' => true,
    'labels' => $resource_cats,
    'show_ui' => true,
    'show_admin_column' => true,
    'query_var' => true,
    'rewrite' => array( 'slug' => 'resource' ),
  ));

}
add_action( 'init', 'resource_categories_taxonomy', 0 );
1

1 Answers

0
votes

You want to edit the design of your taxnonomy, so the way the template structure looks like in wordpress, you should name your file:

taxonomy-resource_categories.php

The taxonomy.php is used if you want to edit the archive page of an taxonomy term, if you add the name of the taxonomy, it will only be used for a specific taxonomy and not all taxonomies. So we had to add the name of your custom taxonomy after.

This is a very useful link for your problem, hope it helps you out: https://developer.wordpress.org/themes/basics/template-hierarchy/