Upload
jesus-garcia-parrado
View
93
Download
0
Embed Size (px)
Citation preview
Jesus Garcia-Parrado
Alameda
Mi propósito es ayudarte para que tu negocio bril le en internet y se mantenga en el tiempo.
Qué os quiero contar hoy
• Qué son los Custom Post Types en WordPress.
• Qué utilidades tienen.
• Varios casos prácticos.
Tipos de Posts por defecto en WordPress
• Post (Post Type: 'post')
• Page (Post Type: 'page')
• Attachment (Post Type: 'attachment')
• Revision (Post Type: ‘revision')
• Custom CSS (Post Type: 'custom_css')
• Changesets (Post Type: 'customize_changeset')
Tipos de Posts por defecto en WordPress
• Post (Post Type: 'post')
• Page (Post Type: 'page')
• Attachment (Post Type: 'attachment')
• Revision (Post Type: ‘revision')
• Custom CSS (Post Type: 'custom_css')
• Changesets (Post Type: 'customize_changeset')
Custom Post Types• Pueden funcionar como posts o como páginas
• Los podemos organizar por categorías, etiquetas o taxonomías personalizadas.
• Tienen una página indice aparte y pueden tener una plantilla personalizada para la página índice.
• Pueden tener todas, ninguna o cualquier combinación de la funcionalidad por defecto para los posts.
• Podemos recuperar estas entradas desde cualquier lugar utilizando un loop personalizado.
¿Cómo se implementa un custom post type?
Mediante un Plugin
• Es la solución mas utilizada.
• Lo puedes utilizar con cualquier theme (plantilla).
• Lo puedes activar y desactivar independientemente del resto de funcionalidad.
¿Cómo se implementa un custom post type?
Mediante un Theme
• En implementaciones personalizadas.
• El contenido depende del theme.
• Permiten construir funcionalidad avanzada.
PluginEsta es la función que utilizaremos para dar de alta nuestro custom post type:
<?php register_post_type( $post_type, $args ); ?>
https://codex.wordpress.org/Function_Reference/register_post_type
En está página podéis encontrar toda la información y un ejemplo completo.
Plugin<?php/** * Plugin Name: Lux Courses * Plugin URI: http://luxdesignworks.com * Description: Custom post type to store and handle Lux courses. * Version: 1.0.0 * Author: Jesus Garcia-Parrado Alameda * Author URI: http://luxdesignworks.com * License: GPL3 + */
Plugin/* Copyright 2016 Jesus Garcia-Parrado Alameda
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation.
This program 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 this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA*/
Pluginfunction lux_course_init() { $labels = array( 'name' => _x( 'Courses', 'post type general name', 'your-plugin-textdomain' ), 'singular_name' => _x( 'Course', 'post type singular name', 'your-plugin-textdomain' ), 'menu_name' => _x( 'Courses', 'admin menu', 'your-plugin-textdomain' ), 'name_admin_bar' => _x( 'Course', 'add new on admin bar', 'your-plugin-textdomain' ), 'add_new' => _x( 'Add New', 'course', 'your-plugin-textdomain' ), 'add_new_item' => __( 'Add New Course', 'your-plugin-textdomain' ), 'new_item' => __( 'New Course', 'your-plugin-textdomain' ), 'edit_item' => __( 'Edit Course', 'your-plugin-textdomain' ), 'view_item' => __( 'View Course', 'your-plugin-textdomain' ), 'all_items' => __( 'All Courses', 'your-plugin-textdomain' ), 'search_items' => __( 'Search Courses', 'your-plugin-textdomain' ), 'parent_item_colon' => __( 'Parent Courses:', 'your-plugin-textdomain' ), 'not_found' => __( 'No courses found.', 'your-plugin-textdomain' ), 'not_found_in_trash' => __( 'No courses found in Trash.', 'your-plugin-textdomain' ) );
Plugin $args = array( 'labels' => $labels, 'description' => __( 'Description.', 'your-plugin-textdomain' ), 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_icon' => 'dashicons-welcome-learn-more', 'query_var' => true, 'rewrite' => array( 'slug' => 'course' ), 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => 5, 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ), 'taxonomies' => array('category','post_tag') );
register_post_type( 'course', $args );}add_action( 'init', 'lux_course_init' );
Pluginfunction lux_rewrite_flush() { lux_course_init(); flush_rewrite_rules();}register_activation_hook( __FILE__, 'lux_rewrite_flush' );}add_action( 'init', 'lux_course_init' );