0

I am trying to create custom template for custom taxonomy. For example i have a custom taxonomy registered in WP with name brands and slug brand i used following code to register custom taxonomy.

function brand() {

$labels = array(
    'name'                       => _x( 'brands', 'Taxonomy General Name',  'text_domain' ),
    'singular_name'              => _x( 'brand', 'Taxonomy Singular Name', 'text_domain' ),
    'menu_name'                  => __( 'Brands', 'text_domain' ),
    'all_items'                  => __( 'All Brands', 'text_domain' ),
    'parent_item'                => __( 'Brand Parent Item', 'text_domain' ),
    'parent_item_colon'          => __( 'Parent Item:', 'text_domain' ),
    'new_item_name'              => __( 'New Brand', 'text_domain' ),
    'add_new_item'               => __( 'Add New Brand', 'text_domain' ),
    'edit_item'                  => __( 'Edit Brand', 'text_domain' ),
    'update_item'                => __( 'Update Brand', 'text_domain' ),
    'view_item'                  => __( 'View Brand', 'text_domain' ),
    'separate_items_with_commas' => __( 'Separate items with commas', 'text_domain' ),
    'add_or_remove_items'        => __( 'Add or remove Brands', 'text_domain' ),
    'choose_from_most_used'      => __( 'Choose from the most used', 'text_domain' ),
    'popular_items'              => __( 'Popular Brands', 'text_domain' ),
    'search_items'               => __( 'Search Brands', 'text_domain' ),
    'not_found'                  => __( 'Not Found', 'text_domain' ),
);
$rewrite = array(
    'slug'                       => 'brand',
    'with_front'                 => true,
    'hierarchical'               => true,
);
$args = array(
    'labels'                     => $labels,
    'hierarchical'               => true,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
    'show_tagcloud'              => true,
    'rewrite'                    => $rewrite,
);
register_taxonomy( 'brand', array( 'product' ), $args );

}

// Hook into the 'init' action
add_action( 'init', 'brand', 0 );

I am trying to create a template to show details of brand taxonomy in a page. i tried creating page templates with name

taxonomy-brand.php   (taxonomy-{slug}.php)
taxonomy-brands.php   (taxonomy-{name}.php)
single-brand.php    (single-{slug}.php)
single-brands.php    (single-{name}.php)

But they are not working and wordpress is showing brand details on single.php instead of showing on a custom template. Please tell me where i am doing wrong.

Thank you

0
0

I think you are using brand taxonomy for the post type product. You should create a file taxonomy-brand.php in your theme directory to display whatever you want in this page. You need not to create page template with this name, only create a file with this name in your theme. If you create any page by name brand please rename or delete it because page details will be open if you created by this name. If you want to display details of the product, create single-product.php in your theme directory.

5
  • hello i already have file taxonomy-brand.php in my theme folder. i echoed this in theme header '<?php echo '<!-- ' . basename( get_page_template() ) . ' -->'; ?>' and it shows that page.php is being used instead of taxonomy-brand.php I am already using single-product.php for showing single product details May 5 '15 at 6:40
  • Have you create any terms like, brandname1, brandname2 ? May 5 '15 at 7:08
  • yes i have added terms/data to brand taxonomy. May 5 '15 at 7:08
  • Which types of url shows ? I have created a terms name philips and my url looks like this /brand/philips/ May 5 '15 at 7:10
  • hello. thank you for your help. i have fixed this issue my self. May 5 '15 at 10:41
0

Just changed permalink settings ti default and then changed them to post_name and then it worked fine. page templates were created fine and taxonomy were registered fine as well. issue was with .htaccess file.

2
  • Please accept your own answer by clicking on the checkmark next to it. It will go green. This means that your question is solved and your answer was the correct one that solved your issue :-) May 7 '15 at 7:02
  • Thank you @Pieter. I thought i cannot mark my answer right myself. May 7 '15 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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