Hey Guys!
I am building a WP site and have categories defined within a post type but can’t work out a way to add a template to display the posts from the categories / taxonomy.
My post type is called product and the taxonomy is category, but the template “taxonomy-category.php” returns nothing in the template.
I have used the basic loop in the template to display the posts.
Any ideas where I am going wrong?
- Community Superstar
- Item was Featured
- Author was Featured
- Has been a member for 5-6 years
- Won a Competition
- Sold between 50 000 and 100 000 dollars
- Bought between 10 and 49 items
- Referred between 50 and 99 users
- Europe
that taxonomy is actually named “category” ? That may be a problem because that term is reserved. Also.. that term can be used together with a slug to show certain a certain category in a custom page: http://codex.wordpress.org/Template_Hierarchy#Category_display
Here is my code for the post type, is it possible to display the name of the taxonomy as category but change the name so it doesn’t clash with the restriction?
add_action( 'init', 'product_post_type' );
function product_post_type() {
$args = array(
'labels' => post_type_labels( 'Product' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'taxonomies' => array('category',),
'supports' => array('title',
'editor',
'author',
'thumbnail',
'excerpt',
'comments'
)
);
register_post_type( 'product', $args );
}
prefix that yo!
- Community Superstar
- Item was Featured
- Author was Featured
- Has been a member for 5-6 years
- Won a Competition
- Sold between 50 000 and 100 000 dollars
- Bought between 10 and 49 items
- Referred between 50 and 99 users
- Europe
'taxonomies' => array('category',),
needs a valid array structure:
'taxonomies' => array('category'),
This is confusing, if I change the name to ‘categories’, the categories disappear so it’s being used.
I have tried the following templates to try and make this work:
taxonomy-category-cat-name.php taxonomy-cat.php taxonomy.php category-cat-name.php
Something is definitely fishy here and it’s not being fair…. arghhhhhh
the category name is reserved by the core…..
how are you registering your tax?
http://codex.wordpress.org/Function_Reference/register_taxonomyMy code as follows (changed name to categories)
add_action( 'init', 'product_post_type' );
function product_post_type() {
$args = array(
'labels' => post_type_labels( 'Product' ),
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => null,
'taxonomies' => array('categories'),
'supports' => array('title',
'editor',
'author',
'thumbnail',
'excerpt',
'comments'
)
);
register_post_type( 'product', $args );
}
function my_taxonomy() {
register_taxonomy(
'categories',
'product',
array(
'hierarchical' => true,
'label' => 'Categories',
'query_var' => true,
'rewrite' => array('slug' => 'category')
)
);
}
add_action( 'init', 'my_taxonomy' );
Try with this :
function my_taxonomy() {
register_taxonomy(__( "product_category" ),
array(__( "product" )),
array(
"hierarchical" => true,
"label" => __( "Categories" ),
"singular_label" => __( "Categories" ),
"rewrite" => array(
'slug' => 'product-category',
'hierarchical' => true
)
)
);
}
and use taxonomy-product_category.php for the product category display.
Sorted it, created a category.php and using a WP Query to grab the current category.
<?php $my_cat = $wp_query->queried_object->name;
$args = array(
'category_name' => $my_cat,
'post_type' => 'product'
);
Thanks for the help everyone.
