Michael A Heap

Custom Wordpress Taxonomies

November 2, 2009 Code, PHPNo Responses on this article

I can't think of any practical applications apart from the one given over at Web Developer Plus - but this is too cool not to share.

The basic example was that if you're running a movie review blog, categories for genre and tags for actors/actresses may work, it would be nicer to have a taxonomy of actors and a taxonomy of genres to categorise them by. Fortunately, it's very simple to add them:

add_action( 'init', 'create_my_taxonomies', 0 );
function create_my_taxonomies() {
	register_taxonomy( 'genre', 'post', array( 'hierarchical' => false, 'label' => 'Genre', 'query_var' => true, 'rewrite' => true ) );
	register_taxonomy( 'actors', 'post', array( 'hierarchical' => false, 'label' => 'Actors', 'query_var' => true, 'rewrite' => true ) );
}

Placing that code in your functions.php file would add two new boxes to your post page in WP2.8+ that lets you add tags within your custom taxonomy. For more information, check out Justin Tadlock's post on Custom Taxonomies

Related posts:

  1. PHP Short Tags
  2. Songs In Code
  3. HTML5 MichaelAHeap.com

Tags: , ,
« »

Leave a Reply