Skip to content

Instantly share code, notes, and snippets.

@whyisjake
Created July 27, 2011 18:41
Show Gist options
  • Save whyisjake/1110062 to your computer and use it in GitHub Desktop.
Save whyisjake/1110062 to your computer and use it in GitHub Desktop.
Taxonomy Conditionals for WordPress
<?php //add this to your functions.php file ?>
<?php
//hook into the init action and call create_maker_taxonomies when it fires
add_action( 'init', 'create_maker_taxonomies', 0 );
//create maker taxonomy for the post type "post"
function create_maker_taxonomies()
{
// Add new taxonomy, NOT hierarchical (like tags)
$labels = array(
'name' => _x( 'Makers', 'taxonomy general name' ),
'singular_name' => _x( 'Maker', 'taxonomy singular name' ),
'search_items' => __( 'Search Makers' ),
'popular_items' => __( 'Popular Makers' ),
'all_items' => __( 'All Makers' ),
'parent_item' => null,
'parent_item_colon' => null,
'edit_item' => __( 'Edit Maker' ),
'update_item' => __( 'Update Maker' ),
'add_new_item' => __( 'Add New Maker' ),
'new_item_name' => __( 'New Maker Name' ),
'separate_items_with_commas' => __( 'Separate makers with commas' ),
'add_or_remove_items' => __( 'Add or remove makers' ),
'choose_from_most_used' => __( 'Choose from the most used makers' ),
'menu_name' => __( 'Makers' ),
);
register_taxonomy('maker','post',array(
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'maker' ),
));
}
?>
<?php //This goes into your template file ?>
<?php if ($taxonomy_exist = taxonomy_exists('maker')); { ?>
<hr>
<h4>Makers in this post:</h4>
<p><?php the_terms( get_the_ID(), 'maker'); ?> </p>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment