Skip to content

Instantly share code, notes, and snippets.

@kirasiris
Last active October 31, 2017 05:24
Show Gist options
  • Save kirasiris/ad36d07816e0bdc21f3303074b548c8d to your computer and use it in GitHub Desktop.
Save kirasiris/ad36d07816e0bdc21f3303074b548c8d to your computer and use it in GitHub Desktop.
<?php
function custom_portfolio_type() {
// Configura las labels para el CPT (custom post type)
$portfolio_labels = array(
'name' => _x( 'Portfolios', 'Post Type General Name', 'kevinurielfonseca' ),
'singular_name' => _x( 'Portfolio', 'Post Type Singular Name', 'kevinurielfonseca' ),
'menu_name' => __( 'Portfolios', 'kevinurielfonseca' ),
'parent_item_colon' => __( 'Parent Portfolio', 'kevinurielfonseca' ),
'all_items' => __( 'All Portfolios', 'kevinurielfonseca' ),
'view_item' => __( 'View Portfolio', 'kevinurielfonseca' ),
'add_new_item' => __( 'Add New Portfolio', 'kevinurielfonseca' ),
'add_new' => __( 'Add Portfolio', 'kevinurielfonseca' ),
'edit_item' => __( 'Edit Portfolio', 'kevinurielfonseca' ),
'update_item' => __( 'Update Portfolio', 'kevinurielfonseca' ),
'search_items' => __( 'Search Portfolio', 'kevinurielfonseca' ),
'not_found' => __( 'Not Found', 'kevinurielfonseca' ),
'not_found_in_trash' => __( 'Not found in Trash', 'kevinurielfonseca' ),
);
// Configura mas opciones para el CPT
$portfolio_args = array(
'label' => __( 'portfolios', 'kevinurielfonseca' ),
'description' => __( 'Portfolio Templates and Snippets', 'kevinurielfonseca' ),
'labels' => $portfolio_labels,
// Caracteristicas con las que contara el CPT
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions','page-attributes','post-formats' ),
// Asocia el CPT con alguna taxonomy
'taxonomies' => array( 'portfolio_categories'),
/* Un CPT jerarquico es como Pages y puede tener
* posts Padres y hijos. Un CPT no jerarquico
* es como Posts.
*/
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'post',
'menu_icon' => 'dashicons-format-gallery',
);
// Registra el CPT. Muy Importante
register_post_type( 'portfolios', $portfolio_args );
}
/* Hook la accion 'init' en orden que la funcion
* que contiene el registro del post type no sea
* innecesariamente ejecutada.
*/
add_action( 'init', 'custom_portfolio_type', 0 );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment