Created
September 30, 2020 22:54
-
-
Save prosantamazumder/017f783ed6402bb766c122b8c000219a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
register_taxonomy('projects_cat', 'projects', array( | |
'labels' => array( | |
'name' => 'Category', | |
'add_new_item' => 'Add New Category', | |
'parent_item' => 'Parent Category', | |
), | |
'public' => true, | |
'hierarchical' => true | |
)); | |
way one | |
=========================== | |
<?php | |
$taxonomy = 'projects_cat'; | |
$terms = get_terms($taxonomy); // Get all terms of a taxonomy | |
if ( $terms && !is_wp_error( $terms ) ) : | |
?> | |
<ul> | |
<?php foreach ( $terms as $term ) { ?> | |
<li><a href="<?php echo get_term_link($term->slug, $taxonomy); ?>"><?php echo $term->name; ?></a></li> | |
<?php } ?> | |
</ul> | |
<?php endif;?> | |
?> | |
//create two taxonomies, genres and tags for the post type "tag" | |
=========================== | |
function create_tag_taxonomies() { | |
// Add new taxonomy, NOT hierarchical (like tags) | |
$labels = array( | |
'name' => _x( 'Tags', 'taxonomy general name' ), | |
'singular_name' => _x( 'Tag', 'taxonomy singular name' ), | |
'search_items' => __( 'Search Tags' ), | |
'popular_items' => __( 'Popular Tags' ), | |
'all_items' => __( 'All Tags' ), | |
'parent_item' => null, | |
'parent_item_colon' => null, | |
'edit_item' => __( 'Edit Tag' ), | |
'update_item' => __( 'Update Tag' ), | |
'add_new_item' => __( 'Add New Tag' ), | |
'new_item_name' => __( 'New Tag Name' ), | |
'separate_items_with_commas' => __( 'Separate tags with commas' ), | |
'add_or_remove_items' => __( 'Add or remove tags' ), | |
'choose_from_most_used' => __( 'Choose from the most used tags' ), | |
'menu_name' => __( 'Tags' ), | |
); | |
register_taxonomy('projects_tag','projects',array( | |
'hierarchical' => false, | |
'labels' => $labels, | |
'show_ui' => true, | |
'update_count_callback' => '_update_post_term_count', | |
'query_var' => true, | |
'rewrite' => array( 'slug' => 'tag' ), | |
)); | |
} | |
add_action( 'init', 'create_tag_taxonomies', 0 ); | |
<?php | |
$terms = wp_get_post_terms($post->ID, 'projects_tag'); | |
if ($terms) { | |
$output = array(); | |
foreach ($terms as $term) { | |
$output[] = '<a>slug .'" href="' .get_term_link( $term->slug, 'projects_tag') .'">' .$term->name .'</a>'; | |
} | |
echo join( ', ', $output ); | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment