Advertisement
ssaidz

Custom Taxonomy Tags for WordPress

Aug 24th, 2016
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.41 KB | None | 0 0
  1. //hook into the init action and call create_topics_nonhierarchical_taxonomy when it fires
  2.  
  3. add_action( 'init', 'create_topics_nonhierarchical_taxonomy', 0 );
  4.  
  5. function create_topics_nonhierarchical_taxonomy() {
  6.  
  7. // Labels part for the GUI
  8.  
  9.   $labels = array(
  10.     'name' => _x( 'Topics', 'taxonomy general name' ),
  11.     'singular_name' => _x( 'Topic', 'taxonomy singular name' ),
  12.     'search_items' =>  __( 'Search Topics' ),
  13.     'popular_items' => __( 'Popular Topics' ),
  14.     'all_items' => __( 'All Topics' ),
  15.     'parent_item' => null,
  16.     'parent_item_colon' => null,
  17.     'edit_item' => __( 'Edit Topic' ),
  18.     'update_item' => __( 'Update Topic' ),
  19.     'add_new_item' => __( 'Add New Topic' ),
  20.     'new_item_name' => __( 'New Topic Name' ),
  21.     'separate_items_with_commas' => __( 'Separate topics with commas' ),
  22.     'add_or_remove_items' => __( 'Add or remove topics' ),
  23.     'choose_from_most_used' => __( 'Choose from the most used topics' ),
  24.     'menu_name' => __( 'Topics' ),
  25.   );
  26.  
  27. // Now register the non-hierarchical taxonomy like tag
  28.  
  29.   register_taxonomy('topics','post',array(
  30.     'hierarchical' => false,
  31.     'labels' => $labels,
  32.     'show_ui' => true,
  33.     'show_admin_column' => true,
  34.     'update_count_callback' => '_update_post_term_count',
  35.     'query_var' => true,
  36.     'rewrite' => array( 'slug' => 'topic' ),
  37.   ));
  38. }
  39.  
  40. <?php the_terms( $post->ID, 'topics', 'Topics: ', ', ', ' ' ); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement