jacodelucia
5/18/2014 - 9:39 AM

WP - Custom post type

WP - Custom post type

function custom_alertes_init() {
  $labels = array(
    'name' 					=> __('Alertes', 'post type general name'),
    'singular_name' 		=> __('Alerte', 'post type singular name'),
    'add_new' 				=> __('Ajouter une nouvelle alerte', 'alerte'),
    'add_new_item' 			=> __('Ajouter une nouvelle alerte'),
    'edit_item' 			=> __('Modifier cette alerte'),
    'new_item' 				=> __('Nouvelle alerte'),
    'all_items' 			=> __('Toutes les alertes'),
    'view_item' 			=> __('Voir l\'alerte'),
    'search_items' 			=> __('Rechercher des alertes'),
    'not_found' 			=> __('Aucune alerte de trouvée'),
    'not_found_in_trash'	=> __('Aucune alerte de trouvée dans la corbeille'), 
    'parent_item_colon' 	=> __(''),
    'menu_name' 			=> __('Alertes')

  );
  $args = array(
    'labels' 				=> $labels,
    'public' 				=> true,
    'publicly_queryable' 	=> true,
    'show_ui' 				=> true, 
    'show_in_menu' 			=> true, 
    'show_in_admin_bar'		=> true,
    'query_var' 			=> true,
    'rewrite' 				=> true,
    'capability_type' 		=> 'post',
    'has_archive' 			=> true, 
    'hierarchical' 			=> false,
    'menu_position' 		=> 11,
    'supports' 				=> array( 'title', 'editor', 'author', 'thumbnail')
  ); 
  register_post_type('alertes',$args);
}
add_action( 'init', 'custom_alertes_init' );

//
// QUERY
//

$query = new WP_query(array('post_type'=>'post', 'posts_per_page'=>4));
while ( $query->have_posts() ) : $query->the_post(); global $post; ?>


# Pour créer une page d'archive de poste type
# -> Simple custom post type archives
# -> créer un fichier type-NOM_DU_TYPE.php