Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- To create a non-hierarchical custom taxonomy like Tags, add this code in your theme’s functions.php or in a site-specific plugin:
- =================
- //hook into the init action and call create_topics_nonhierarchical_taxonomy when it fires
- add_action( 'init', 'create_topics_nonhierarchical_taxonomy', 0 );
- function create_topics_nonhierarchical_taxonomy() {
- // Labels part for the GUI
- $labels = array(
- 'name' => _x( 'Topics', 'taxonomy general name' ),
- 'singular_name' => _x( 'Topic', 'taxonomy singular name' ),
- 'search_items' => __( 'Search Topics' ),
- 'popular_items' => __( 'Popular Topics' ),
- 'all_items' => __( 'All Topics' ),
- 'parent_item' => null,
- 'parent_item_colon' => null,
- 'edit_item' => __( 'Edit Topic' ),
- 'update_item' => __( 'Update Topic' ),
- 'add_new_item' => __( 'Add New Topic' ),
- 'new_item_name' => __( 'New Topic Name' ),
- 'separate_items_with_commas' => __( 'Separate topics with commas' ),
- 'add_or_remove_items' => __( 'Add or remove topics' ),
- 'choose_from_most_used' => __( 'Choose from the most used topics' ),
- 'menu_name' => __( 'Topics' ),
- );
- // Now register the non-hierarchical taxonomy like tag
- register_taxonomy('topics','post',array(
- 'hierarchical' => false,
- 'labels' => $labels,
- 'show_ui' => true,
- 'show_admin_column' => true,
- 'update_count_callback' => '_update_post_term_count',
- 'query_var' => true,
- 'rewrite' => array( 'slug' => 'topic' ),
- ));
- }
- Kode menampilkan di web, masukkan ke single.php:
- <?php the_terms( $post->ID, 'topics', 'Topics: ', ', ', ' ' ); ?>
- kunci: http://www.wpbeginner.com/wp-tutorials/create-custom-taxonomies-wordpress/
- =============================================
- =============================================
- INI YANG BISA
- =============================================
- =============================================
- //create a function that will attach our new 'penulis' taxonomy to the 'post' post type
- function add_penulis_taxonomy_to_post(){
- //set the name of the taxonomy
- $taxonomy = 'penulis';
- //set the post types for the taxonomy
- $object_type = 'post';
- //populate our array of names for our taxonomy
- $labels = array(
- 'name' => 'penulis',
- 'singular_name' => 'penulis',
- 'search_items' => 'Search penulis',
- 'all_items' => 'All penulis',
- 'parent_item' => 'Parent penulis',
- 'parent_item_colon' => 'Parent penulis:',
- 'update_item' => 'Update penulis',
- 'edit_item' => 'Edit penulis',
- 'add_new_item' => 'Add New penulis',
- 'new_item_name' => 'New penulis Name',
- 'menu_name' => 'penulis'
- );
- //define arguments to be used
- $args = array(
- 'labels' => $labels,
- 'hierarchical' => false,
- 'show_ui' => true,
- 'how_in_nav_menus' => true,
- 'public' => true,
- 'show_admin_column' => true,
- 'query_var' => true,
- 'rewrite' => array('slug' => 'penulis')
- );
- //call the register_taxonomy function
- register_taxonomy($taxonomy, $object_type, $args);
- }
- add_action('init','add_penulis_taxonomy_to_post');
- Kode menampilkan di web, masukkan ke single.php:
- <?php the_terms( $post->ID, 'topics', 'Topics: ', ', ', ' ' ); ?>
- DIambil dar: https://generatewp.com/taxonomy/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement