Skip to content

Instantly share code, notes, and snippets.

@DavidPeralvarez DavidPeralvarez/plugin-cpt.php Secret
Created Jun 22, 2018

Embed
What would you like to do?
La función register_taxonomy y los "labels"
<?php
/*
Plugin Name: Plugin CPT y Custom Taxonomies
Plugin URI: https://silicodevalley.com
Description: Plugin para aprender a crear CPT y CT con código
Version: 1.0.0
Author: David Perálvarez
Author URI: https://silicodevalley.com
License: GPL2
License URI: https://www.gnu.org/licenses/gpl-2.0.html
*/
/*
Plugin CPT y Custom Taxonomies is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
any later version.
Plugin CPT y Custom Taxonomies is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Plugin CPT y Custom Taxonomies. If not, see https://www.gnu.org/licenses/gpl-2.0.html.
*/
// Comic Reviews
function comic_review_setup_post_type(){
$labels = array(
'name' => __( 'Reseñas', 'scv' ),
'singular_name' => __( 'Reseña', 'scv' ),
'add_new' => __( 'Añadir reseña', 'scv' ),
'add_new_item' => __( 'Añadir nueva reseña', 'scv' ),
'edit_item' => __( 'Editar reseña', 'scv' ),
'new_item' => __( 'Nueva reseña', 'scv' ),
'view_item' => __( 'Ver reseña', 'scv' ),
'view_items' => __( 'Ver reseñas', 'scv' ),
'search_items' => __( 'Buscar reseñas', 'scv' ),
'not_found' => __( 'No se encontraron reseñas', 'scv' ),
'not_found_in_trash' => __( 'Ninguna reseña encontrada en la papelera', 'scv' ),
'all_items' => __( 'Todas las reseñas', 'scv' ),
'insert_into_item' => __( 'Insertar en la reseña', 'scv' ),
'filter_items_list' => __( 'Lista de reseñas filtrada', 'scv' ),
'items_list_navigation' => __( 'Navegación por el listado de reseñas', 'scv' ),
'items_list' => __( 'Lista de reseñas', 'scv' ),
);
$args = array(
'public' => true,
'labels' => $labels,
'menu_position' => 5,
'menu_icon' => 'dashicons-star-half',
'hierarchical' => false,
'supports' => array(
'title','editor','author','thumbnail','excerpt','custom-fields','comments','revisions',
),
'has_archive' => true,
'rewrite' => array(
'slug' => __( 'reviews', 'scv' ),
),
);
// poner prefijo, max 20
register_post_type( 'scv_comic_review', $args );
// Author Taxonomy
$labelsAuthor = array(
'name' => __( 'Autores', 'scv' ),
'singular_name' => __( 'Autor', 'scv' ),
//'menu_name' => __( 'Autores', 'scv' ), //default: 'name'
'all_items' => __( 'Todos los autores', 'scv' ),
'edit_item' => __( 'Editar autor', 'scv' ),
'view_item' => __( 'Ver autor', 'scv' ),
'update_item' => __( 'Actualizar autor', 'scv' ),
'add_new_item' => __( 'Añadir nuevo autor', 'scv' ),
'new_item_name' => __( 'Nombre del nuevo autor', 'scv' ),
//'parent_item' => __( 'Autor Padre', 'scv' ), //jerárquica
//'parent_item_colon' => __( 'Autor Padre:', 'scv' ), //jerárquica
'search_items' => __( 'Buscar autores', 'scv' ),
'popular_items' => __( 'Autores populares', 'scv' ), //no jerárquica
'add_or_remove_items' => __( 'Añadir o eliminar autores', 'scv' ), //no jerárquica / no javascript
'choose_from_most_used' => __( 'Elegir entre los autores más utilizados', 'scv' ),
'not_found' => __( 'No se han encontrado autores.', 'scv' ),
);
$argsAuthor = array(
'public' => true,
'labels' => $labelsAuthor,
);
// poner prefijo, max 32
register_taxonomy( 'scv_comic_author', array('scv_comic_review'), $argsAuthor );
register_taxonomy_for_object_type( 'scv_comic_author', 'scv_comic_review');
// Genre Taxonomy
$labelsGenre = array(
'name' => __( 'Géneros', 'scv' ),
'singular_name' => __( 'Género', 'scv' ),
'all_items' => __( 'Todos los géneros', 'scv' ),
'edit_item' => __( 'Editar género', 'scv' ),
'view_item' => __( 'Ver género', 'scv' ),
'update_item' => __( 'Actualizar género', 'scv' ),
'add_new_item' => __( 'Añadir nuevo género', 'scv' ),
'new_item_name' => __( 'Nombre del nuevo género', 'scv' ),
'parent_item' => __( 'Género Padre', 'scv' ), //jerárquica
'parent_item_colon' => __( 'Género Padre:', 'scv' ), //jerárquica
'search_items' => __( 'Buscar géneros', 'scv' ),
'choose_from_most_used' => __( 'Elegir entre los géneros más utilizados', 'scv' ),
'not_found' => __( 'No se han encontrado géneros.', 'scv' ),
);
$argsGenre = array(
'public' => true,
'labels' => $labelsGenre,
);
// poner prefijo, max 32
register_taxonomy( 'scv_comic_genre', array('scv_comic_review'), $argsGenre );
register_taxonomy_for_object_type( 'scv_comic_genre', 'scv_comic_review');
}
add_action( 'init', 'comic_review_setup_post_type' );
// Flushing Rewrite on Activation/Deactivation (plugin)
register_deactivation_hook( __FILE__, 'flush_rewrite_rules' );
register_activation_hook( __FILE__, 'scv_rewrite_flush' );
// Flushing Rewrite on switch theme
//add_action( 'after_switch_theme', 'scv_rewrite_flush' );
function scv_rewrite_flush(){
comic_review_setup_post_type();
// limpia las reglas de reescritura (enlace permanentes)
// actualiza el fichero .htaccess
flush_rewrite_rules();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.