giovedì 10 ottobre 2013

Creare un nuovo Post Type

Ad esempio un post type "Issuu":

Codice su function.php

add_action( 'init', 'ts_issuu_cpt_register' );

function ts_issuu_cpt_register() {

    $labels = array(
        'name' => _x( 'Issuu', 'issuu' ),
        'singular_name' => _x( 'Issuu', 'issuu' ),
        'add_new' => _x( 'Add New', 'Issuu' ),
        'add_new_item' => _x( 'Add New Issuu', 'issuu' ),
        'edit_item' => _x( 'Edit Issuu', 'issuu' ),
        'new_item' => _x( 'New Isuu', 'issuu' ),
        'view_item' => _x( 'View Isuu', 'issuu' ),
        'search_items' => _x( 'Search Isuu', 'issuu' ),
        'not_found' => _x( 'No issus found', 'issuu' ),
        'not_found_in_trash' => _x( 'No issuu found in Trash', 'video' ),
        'parent_item_colon' => _x( 'Parent Issuu:', 'issuu' ),
        'menu_name' => _x( 'Issuu', 'issuu' ),
    );

    $args = array(
        'labels' => $labels,
        'hierarchical' => false,      
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'custom-fields'),
        'taxonomies' => array( 'category' ),
        'public' => true,
        'show_ui' => true,
        'show_in_menu' => true,
        'menu_position' => 6,
        'show_in_nav_menus' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'has_archive' => true,
        'query_var' => true,
        'can_export' => true,
        'rewrite' => true,
        'capability_type' => 'post'
    );

    register_post_type( 'issuu', $args );
   
    flush_rewrite_rules();
}

Da notare che si modifica la funziona da loggato per vedere le novità bisogna sloggarsi e entrare di nuovo.

Alcune caratteristiche:

       'taxonomies' => array( 'category' ) per usare le categorie di default 

Nessun commento: