prestations_services
create prestations/services post type
// Add custom Post Type (Prestation ) function coh_prestations() { $labels = array( 'name' => _x( 'Prestations', 'Post Type General Name', 'coh_prestations' ), 'singular_name' => _x( 'Prestation', 'Post Type Singular Name', 'coh_prestations' ), 'menu_name' => __( 'Prestations', 'coh_prestations' ), 'name_admin_bar' => __( 'Prestation', 'coh_prestations' ), 'archives' => __( 'Archives du Prestation', 'coh_prestations' ), 'attributes' => __( 'Attributs du Prestation', 'coh_prestations' ), 'parent_item_colon' => __( 'Parent du Prestation :', 'coh_prestations' ), 'all_items' => __( 'Tous les Prestations', 'coh_prestations' ), 'add_new_item' => __( 'Ajouter une nouvelle Prestation', 'coh_prestations' ), 'add_new' => __( 'Ajouter une Prestation', 'coh_prestations' ), 'new_item' => __( 'Nouvelle Prestation', 'coh_prestations' ), 'edit_item' => __( 'Modifier la Prestation', 'coh_prestations' ), 'update_item' => __( 'Mettre à jour la Prestation', 'coh_prestations' ), 'view_item' => __( 'Voir la prestation', 'coh_prestations' ), 'view_items' => __( 'Voir les prestations', 'coh_prestations' ), 'search_items' => __( 'Rechercher une Prestation', 'coh_prestations' ), 'not_found' => __( 'Pas trouvé', 'coh_prestations' ), 'not_found_in_trash' => __( 'Introuvable dans la corbeille', 'coh_prestations' ), 'featured_image' => __( 'L'image sélectionnée', 'coh_prestations' ), 'set_featured_image' => __( 'Définir l'image sélectionnée', 'coh_prestations' ), 'remove_featured_image' => __( 'Supprimer l'image sélectionnée', 'coh_prestations' ), 'use_featured_image' => __( 'Utiliser comme image vedette', 'coh_prestations' ), 'insert_into_item' => __( 'Insérer dans Prestation', 'coh_prestations' ), 'uploaded_to_this_item' => __( 'Téléchargé sur cette Prestation', 'coh_prestations' ), 'items_list' => __( 'Liste des prestations', 'coh_prestations' ), 'items_list_navigation' => __( 'Navigation des prestations', 'coh_prestations' ), 'filter_items_list' => __( 'Filtrer la liste des Prestations', 'coh_prestations' ), ); $rewrite = array( 'slug' => 'prestation', 'with_front' => true, 'pages' => true, 'feeds' => true, ); $args = array( 'label' => __( 'Prestation', 'coh_prestations' ), 'description' => __( 'Créer des prestations et des services de l'entreprise', 'coh_prestations' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'thumbnail', 'revisions', 'custom-fields', 'page-attributes', 'post-formats' ), 'hierarchical' => true, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 5, 'menu_icon' => 'dashicons-list-view', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => 'archive-prestations', 'exclude_from_search' => false, 'publicly_queryable' => true, 'rewrite' => $rewrite, 'capability_type' => 'page', ); register_post_type( 'coh_prestations', $args ); } add_action( 'init', 'coh_prestations', 0 ); // Shortcode to Display all Prestations (example [prestations-list]) function coh_prestations_list($attr){ $args = array( 'post_type' => 'coh_prestations', 'posts_per_page' => '10', 'publish_status' => 'published', ); $query = new WP_Query($args); if($query->have_posts()) : while($query->have_posts()) : $query->the_post() ; $result .= '<div class="prestation-item">'; $result .= '<div class="prestation-poster">' . get_the_post_thumbnail() . '</div>'; $result .= '<div class="prestation-name">' . get_the_title() . '</div>'; $result .= '<div class="prestation-desc">' . get_the_content() . '</div>'; $result .= '</div>'; endwhile; wp_reset_postdata(); endif; return $result; } add_shortcode( 'prestations-list', 'coh_prestations_list' ); // Shortcode to Display one Prestation by id (example [prestation-post id="37"]) function coh_prestation_post($atts) { $atts = shortcode_atts( array( 'id' => '', 'post_type' => 'coh_prestations', ), $atts ); $post_id = $atts['id']; $result .= '<div class="prestation-item">'; $result .= '<div class="prestation-poster">' . get_the_post_thumbnail($post_id, 'large') . '</div>'; $result .= '<div class="prestation-name">' . get_the_title($post_id) . '</div>'; $result .= '<div class="prestation-desc">' . get_the_content($post_id) . '</div>'; $result .= '</div>'; return $result; } add_shortcode( 'prestation-post', 'coh_prestation_post' );