Taxonomy template file in custom theme
-
Hi,
I am trying to build a WP website with a custom theme which I am trying to code from scratch.
Most of it is coming together fine but I am really stumped on taxonomy templates.
I have create a custom post type of products and a custom taxonomy related to products called product-type. Now I am trying to get a list of all the products in a particular product-type which I believe should mean creating a taxonomy.php file in the theme and doing all the code in there, however whenever I visit the taxonomy page I just get the default index.php page.
I have used the following code to pull out the URL’s for the taxonomy terms so the URL’s should be correct.
$product_types = get_terms('product_type', 'orderby=count&hide_empty=0'); foreach($product_types as $product_type) { echo '<p>' .$product_type->name. ' - ' .$product_type->slug. '</p>'; }
In my functions file I have create the products custom post type and the product_type custom taxonomy using the following code:
register_taxonomy( 'product_type', 'products', array( 'label' => __('Product Type'), 'sort' => true, 'rewrite' => array( 'slug' => 'product-type', 'with_front' => false ) )
register_post_type( 'products', array( 'labels' => array ( 'name' => __('Products'), 'singular_name' => __('Product') ), 'public' => true, 'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields' ), 'taxonomies' => array( 'product_type' ) ) );
- The topic ‘Taxonomy template file in custom theme’ is closed to new replies.