Let’s say you have a blog, and on that blog you post recipes. Each time you post a recipe you file it under one or more tags—salads, soups, desserts, chicken, fish, Italian, Mexican, pasta, or another tag that’s appropriate.
Whenever you post anything on your blog, whether it’s a recipe or not, you tag it. Tags are a useful way of grouping related posts together. Readers can quickly tell what the post is about, or they can click on the tag to see a list of related posts they might be interested in reading.
Now let’s say, you want only the tags for your recipes to appear in your sidebar. The default tag cloud in the WordPress widget area will pick up tags for all of your posts, not just for recipes.
What you need is a custom taxonomy especially for “recipes.”
Here’s how to do it
IMPORTANT: In all cases, if you change the name of the taxonomy from recipes to something else, be sure to change every instance of “recipes” in the code.
- Create the custom taxonomy by adding the following code to your functions.php:
/** Register custom taxonomy */ add_action( 'init', 'register_taxonomy_recipes' ); function register_taxonomy_recipes() { $labels = array( 'name' => _x( 'Recipes', 'recipes' ), 'singular_name' => _x( 'Recipes', 'recipes' ), 'search_items' => _x( 'Search Recipes', 'recipes' ), 'popular_items' => _x( 'Popular Recipes', 'recipes' ), 'all_items' => _x( 'All Recipes', 'recipes' ), 'parent_item' => _x( 'Parent Recipes', 'recipes' ), 'parent_item_colon' => _x( 'Parent Recipes:', 'recipes' ), 'edit_item' => _x( 'Edit Recipes', 'recipes' ), 'update_item' => _x( 'Update Recipes', 'recipes' ), 'add_new_item' => _x( 'Add New Recipes', 'recipes' ), 'new_item_name' => _x( 'New Recipes', 'recipes' ), 'separate_items_with_commas' => _x( 'Separate recipes with commas', 'recipes' ), 'add_or_remove_items' => _x( 'Add or remove recipes', 'recipes' ), 'choose_from_most_used' => _x( 'Choose from most used recipes', 'recipes' ), 'menu_name' => _x( 'Recipes', 'recipes' ), ); $args = array( 'labels' => $labels, 'public' => true, 'show_in_nav_menus' => true, 'show_ui' => true, 'show_tagcloud' => true, 'show_admin_column' => true, 'hierarchical' => true, 'rewrite' => true, 'query_var' => true ); register_taxonomy( 'recipes', array('post'), $args ); }
- To have the new custom taxonomy appear at the bottom of your posts, add the following code to your functions.php:
/** Customize post meta function */ add_filter( 'genesis_post_meta', 'post_meta_filter' ); function post_meta_filter($post_meta) { if ( !is_page() ) { $post_meta = '
'; return $post_meta; } } - The default number of tags in a tag cloud is 45. If you have more than 45 tags and want all of the tags to appear, add the following code to functions.php:
/** Change number of tags in tag cloud */ add_filter( 'widget_tag_cloud_args', 'custom_tag_cloud_widget' ); function custom_tag_cloud_widget($args) { $args['number'] = 0; //adding a 0 will display all tags $args['exclude'] = array(); //exclude or include tags by ID return $args; }
- SAVE your updated functions file. Then—and this is important—go to your Dashboard >> Settings >> Permalinks and SAVE.
That’s it. Your new custom taxonomy will be listed in your Dashboard menu on the left under Posts. When you write a new post, you’ll find Tags and Recipes on the right side of the edit screen. To add a tag to the new taxonomy, click Add New Recipes. If the tag you want is already listed, just check the box. On existing recipes, delete tags and create new ones using the new custom taxonomy. If you want to use both tags and the new taxonomy, you’ll have to further customize the meta function.
Any questions, just ask.