• User Attivo

    Inserire Tassonomia

    Ho trovato questo interessante articolo che sembra funzionare anche se risale a settembre 2013 ma di più recenti ne ho trovati pochi e non funzionano...

    Mi funziona tutto con questo codice

    [php]function add_custom_taxonomies() { register_taxonomy('genre', 'post', array( 'hierarchical' => true, 'labels' => array( 'name' => _x('Genres', 'taxonomy general name' ), 'singular_name' => _x('Genre', 'taxonomy singular name' ), 'search_items' => __('Search Genres' ), 'all_items' => __( 'All Genres' ), 'parent_item' => __( 'Parent Genre' ), 'parent_item_colon' => __( 'Parent Genre:' ), 'edit_item' => __( 'Edit Genre' ), 'update_item' => __( 'Update Genre' ), 'add_new_item' => __( 'Add New Genre' ), 'new_item_name' => __( 'New Genre Name' ), 'menu_name' => __( 'Genres' ), ), 'rewrite' => array( 'slug' => 'Genres', 'with_front' => false, 'hierarchical' => true ), )); } add_action( 'init', 'add_custom_taxonomies', 0 );[/php]
    Unica cosa che non ho capito è come fare per inserire più tassonomie... Con questo codice inserisco la tassonomia Genres, per inserire Genres2 come devo modificare il codice? Grazie


  • Moderatore

    Ciao risca5,
    puoi aggiungere semplicemente una nuova tassonomia, direttamente nella funzione. Ipotizzando Genre2 la aggiungi in questo modo:
    [PHP]
    <?php
    function add_custom_taxonomies() {
    register_taxonomy('genre', 'post', array(
    'hierarchical' => true,
    'labels' => array(
    'name' => _x('Genres', 'taxonomy general name' ),
    'singular_name' => _x('Genre', 'taxonomy singular name' ),
    'search_items' => __('Search Genres' ),
    'all_items' => __( 'All Genres' ),
    'parent_item' => __( 'Parent Genre' ),
    'parent_item_colon' => __( 'Parent Genre:' ),
    'edit_item' => __( 'Edit Genre' ),
    'update_item' => __( 'Update Genre' ),
    'add_new_item' => __( 'Add New Genre' ),
    'new_item_name' => __( 'New Genre Name' ),
    'menu_name' => __( 'Genres' ),
    ),
    'rewrite' => array(
    'slug' => 'Genres',
    'with_front' => false,
    'hierarchical' => true
    ),
    )
    );

    register_taxonomy('genre2', 'post', array(
    	'hierarchical' => true,
    	'labels' => array(
    		'name' => _x('Genres2', 'taxonomy general name' ),
    		'singular_name' => _x('Genre2', 'taxonomy singular name' ),
    		'search_items' => __('Search Genres2' ),
    		'all_items' => __( 'All Genres2' ),
    		'parent_item' => __( 'Parent Genre2' ),
    		'parent_item_colon' => __( 'Parent Genre2:' ),
    		'edit_item' => __( 'Edit Genre2' ),
    		'update_item' => __( 'Update Genre2' ),
    		'add_new_item' => __( 'Add New Genre2' ),
    		'new_item_name' => __( 'New Genre2 Name' ),
    		'menu_name' => __( 'Genres2' ),
    	),
    	'rewrite' => array(
    		'slug' => 'Genres2',
    		'with_front' => false,
    		'hierarchical' => true
    	),
    )
    );
    

    }
    add_action( 'init', 'add_custom_taxonomies', 0 );
    [/PHP]


  • Moderatore

    Sono molto interessato all'argomento.

    Devo sistemare un sito wordpress in cui nelle categorie ho genere e luogo.
    Ad esempio un articolo può parlare di agricoltura in Lombardia; Agricoltura e Lombardia sono 2 categorie distinte.

    Quindi vorrei dividere le categorie in due gruppi: genere e luogo.

    La soluzione sopracitata fa al caso mio?


  • User Attivo

    Se ne hai tanti si, se no puoi usare semplicemente delle categorie.