Add a Taxonomy Products or Projects to a WordPress Theme

taxno

Step 1. Create folder in your theme called ‘inc’
Step 2. Create file called tax-products.php
Step 3.  Inside the file copy and paste the following. Then save the file.

<?php
function cpt_products(){
global $options;
$url_rewrite = $options[‘theme_product_item_url’];
if( !$url_rewrite ) { $url_rewrite = ‘products’; }
register_post_type(‘post_products’,
array(
‘labels’ => array(
‘name’ => ‘Products’,
‘singular_name’ => ‘Product Item’,
‘add_new’ => ‘Add New Product’,
‘add_new_item’ => ‘Add New Product Item’,
‘edit’ => ‘Edit’,
‘edit_item’ => ‘Edit Product Item’,
‘new_item’ => ‘New Product Item’,
‘view’ => ‘View’,
‘view_item’ => ‘View Product Item’,
‘search_items’ => ‘Search Product Items’,
‘not_found’ => ‘No product items found’,
‘not_found_in_trash’ => ‘No product items found in Trash’,
‘parent’ => ‘Parent Product Item’
),
‘description’ => ‘Easily lets you create some beautiful products.’,
‘public’ => true,
‘show_ui’ => true,
‘_builtin’ => false,
‘capability_type’ => ‘page’,
‘hierarchical’ => true,
‘rewrite’ => array(‘slug’ => $url_rewrite),
‘supports’ => array(‘title’, ‘editor’, ‘thumbnail’, ‘comments’),
)
);
flush_rewrite_rules();
}
function tax_products() {
global $options;
$url_rewrite = $options[‘theme_product_item_type_url’];
if( !$url_rewrite ) { $url_rewrite = ‘item-type’; }
register_taxonomy(‘products_item_types’, ‘post_products’,
array(
‘hierarchical’ => true,
‘labels’ => array(
‘name’ => ‘Item Types’,
‘singular_name’ => ‘Item Types’,
‘search_items’ => ‘Search Types’,
‘popular_items’ => ‘Popular Types’,
‘all_items’ => ‘All Types’,
‘parent_item’ => ‘Parent Types’,
‘parent_item_colon’ => ‘Parent Type:’,
‘edit_item’ => ‘Edit Type’,
‘update_item’ => ‘Update Type’,
‘add_new_item’ => ‘Add New Type’,
‘new_item_name’ => ‘New Type Name’
),
‘show_ui’ => true,
‘query_var’ => true,
‘rewrite’ => array(‘slug’ => $url_rewrite)
)
);
flush_rewrite_rules();
}

add_action(‘init’, ‘cpt_products’);
add_action(‘init’, ‘tax_products’);

Step 4. Add the following line to the function.php


include_once( get_template_directory() . '/inc/tax-projects.php' );

This entry was posted in Wordpress. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *