Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Définition des types de contenus, taxonomies, metaboxes et custom fields
- */
- // Type de contenu Livre
- $book = register_cuztom_post_type(
- 'Livre',
- array(
- 'menu_icon' => get_template_directory_uri() . '/img/book.png'
- )
- );
- $book->add_taxonomy('Genre');
- // Ajouter une metabox et plusieurs champs
- $book->add_meta_box(
- 'book_info',
- 'Information sur ce livre',
- array(
- array(
- 'name' => 'publication_date',
- 'label' => 'Date de publication',
- 'type' => 'date',
- 'description' => 'Description qui va sous le titre',
- 'explanation' => 'Explication qui va sous le champs',
- ),
- array(
- 'name' => 'cover',
- 'label' => 'Couverture du livre',
- 'type' => 'image',
- 'description' => 'Envoyez une image de couverture du livre',
- ),
- array(
- 'type' => 'post_select',
- 'name' => 'author',
- 'label' => 'Auteur du livre',
- 'args' => array(
- 'post_type' => 'auteur',
- 'posts_per_page' => -1
- )
- )
- )
- );
- // Type de contenu Auteur
- $author = register_cuztom_post_type(
- 'Auteur',
- array(
- 'menu_icon' => get_template_directory_uri() . '/img/pencil.png'
- )
- );
- /*
- * Modification des colonnes d'administration des livres
- */
- function custom_livre_columns_title($columns) {
- $columns['publication_date'] = 'Date de pub.';
- $columns['title'] = 'Titre du livre';
- $columns['date'] = 'Article publié le';
- $columns['genre'] = 'Genres';
- $columns = array_slice($columns, 0, 1, true) + array('livre_cover' => 'Couverture de livre') + array_slice($columns, 1, count($columns) - 1, true);
- return $columns;
- }
- add_filter('manage_edit-livre_columns', 'custom_livre_columns_title');
- function custom_livre_columns_content($column) {
- global $post;
- switch ($column) {
- case 'livre_cover':
- $image_id = get_post_meta($post->ID, '_book_info_cover', true);
- $image = wp_get_attachment_image_src($image_id, 'full');
- $image_src = $image[0];
- if (isset($image_id) && $image_id != '') { ?>
- <img style="width:75px;height:auto;" src="<?php echo esc_url($image_src); ?>" alt="<?php echo esc_attr(get_the_title($post->ID)); ?>" />
- <?php }
- break;
- case 'publication_date':
- echo get_post_meta($post->ID, '_book_info_publication_date', true);
- break;
- case 'genre' :
- echo get_the_term_list($post->ID, 'genre', '', ', ', '');
- break;
- }
- }
- add_action('manage_livre_posts_custom_column', 'custom_livre_columns_content');
- /*
- * Modification des colonnes d'administration des auteurs
- */
- function custom_auteur_columns_title($columns) {
- $columns['number_books'] = 'Nombre de livres';
- return $columns;
- }
- add_filter('manage_edit-auteur_columns', 'custom_auteur_columns_title');
- function custom_auteur_columns_content($column) {
- global $post;
- switch ($column) {
- case 'number_books':
- $args = array(
- 'post_type' => 'livre',
- 'numberposts' => -1,
- 'meta_query' => array(
- array(
- 'key' => '_book_info_author',
- 'value' => $post->ID
- )
- )
- );
- $books = get_posts($args);
- echo count($books);
- break;
- }
- }
- add_action('manage_auteur_posts_custom_column', 'custom_auteur_columns_content');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement