サポート » 使い方全般 » tag機能の削除 or tagのhierarchical化(階層化)の方法について

  • wordpressの投稿タイプpostにはcategoryとtagの二つのtaxonomyが有りますが、tagをcategoryのように階層化して使用したいと考えています。

    tagを階層化する方法か、tag機能を削除して、hierarchicalなカスタムタクソノミーを追加するか、どちらかの方法をとりたいのですが、どのようなコードをfunctions.phpに書けばいいか教えてください。(taxonmyの追加の仕方は分かります)

    1.tagをhierarchicalに変更する方法

    2.tag機能を削除する方法

    このどちらか or 両方を教えて頂けるよう、お手数ですが、お願いします。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • モデレーター jim912

    (@jim912)

    1.

    function re_register_post_tag_taxonomy() {
    	global $wp_rewrite;
    	$rewrite = array(
    		'slug' => get_option('tag_base') ? get_option('tag_base') : 'tag',
    		'with_front' => ! get_option('tag_base') || $wp_rewrite->using_index_permalinks(),
    		'ep_mask' => EP_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' ),
    		'view_item' => __( 'View 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' ),
    		'not_found' => __( 'No tags found.' )
    	);
    
    	register_taxonomy( 'post_tag', 'post', array(
    	 	'hierarchical' => true,
    		'query_var' => 'tag',
    		'rewrite' => $rewrite,
    		'public' => true,
    		'show_ui' => true,
    		'show_admin_column' => true,
    		'_builtin' => true,
    		'labels' => $labels
    	) );
    }
    add_action( 'init', 're_register_post_tag_taxonomy', 1 );

    2.

    function remove_post_tag_taxonomy() {
    	global $wp_taxonomies;
    	if ( isset( $wp_taxonomies['post_tag'] ) ) {
    		unset( $wp_taxonomies['post_tag'] );
    	}
    }
    add_action( 'init', 'remove_post_tag_taxonomy', 1 );

    ご利用は自己責任で。

1件の返信を表示中 - 1 - 1件目 (全1件中)
  • トピック「tag機能の削除 or tagのhierarchical化(階層化)の方法について」には新たに返信することはできません。