Hello,
I'm not really sure about the section but I tried.
For a week now, I'my trying to use que custom post type correctly for my project.
But now, I managed to do what I need for the single page.
I need one more thing and this is for the archive page.
Is it possible to group the post type by month with only one wp-query or do I need to create one request for one month on my side and update it every month?
And how to display a field on the archive page like the date?
Here is the code for my page-cruises.php
<?php
/*Template Name: Cruises list*/
get_header(); ?>
<div id="primary" class="content-area eight columns">
<div id="content" class="site-content" role="main">
<article class="hentry">
<?php
if ( function_exists('yoast_breadcrumb') )
{
yoast_breadcrumb('<p id="breadcrumbs">','</p>');
}
?>
<?php $loop = new WP_Query(array( 'post_type' => 'cruises', 'posts_per_page' => 10, 'order' => 'ASC' )); ?>
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<header class="entry-header">
<?php the_title( '<h1 class="entry-title"><a href="' . get_permalink() . '" title="' . the_title_attribute( 'echo=0' ) . '" rel="bookmark">', '</a></h1>' ); ?>
</header>
<div class="entry-content">
<?php the_excerpt(); ?>
</div>
<?php endwhile; ?>
</article>
</div><!-- #content .site-content -->
</div><!-- #primary .content-area -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>
and the custom post type on function.php :
add_action('init', 'cruises_init');
function cruises_init()
{
$labels = array
(
'name' => _x('Croisières', 'post type general name'),
'singular_name' => _x('Croisière', 'post type singular name'),
'add_new' => _x('Ajouter nouvelle', 'portfolio item'),
'add_new_item' => __('Ajouter nouvelle croisière'),
'edit_item' => __('Modifier croisière'),
'new_item' => __('Nouvelle croisière'),
'view_item' => __('Voir croisière'),
'search_items' => __('Chercher croisière'),
'not_found' => __('Rien trouvé'),
'not_found_in_trash' => __('Rien trouvé dans la poubelle'),
'parent_item_colon' => ''
);
$args = array
(
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => null,
'supports' => array('title', 'editor', 'thumbnail', 'revisions', 'page-attributes')
);
register_post_type( 'cruises' , $args );
register_taxonomy("Armateur", array("cruises"), array("hierarchical" => true, "label" => "Armateurs", "singular_label" => "Armateur", "rewrite" => true));
add_action("admin_init", "admin_init");
function admin_init(){
add_meta_box("cruises_titles", "Titres de la croisière", "cruises_titles", "cruises", "normal", "low");
add_meta_box("cruises_details", "Détails de la croisière", "cruises_details", "cruises", "normal", "low");
add_meta_box("cabins", "Cabines", "cabins", "cruises", "normal", "low");
}
function cruises_titles()
{
global $post;
$custom = get_post_custom($post->ID);
$slogan = $custom["slogan"][0];
$theme = $custom["theme"][0];
?>
<p><label>Slogan :</label><br />
<input type="text" name="slogan" value="<?php echo $slogan; ?>" /></p>
<p><label>Thème :</label><br />
<input type="text" name="theme" value="<?php echo $theme; ?>" /></p>
<?php
}
function cruises_details()
{
global $post;
$custom = get_post_custom($post->ID);
$ship = $custom["ship"][0];
$travel = $custom["travel"][0];
$departure = $custom["departure"][0];
$duration = $custom["duration"][0];
$price = $custom["price"][0];
$details = $custom["details"][0];
?>
<p><label>Navire :</label><br />
<input type="text" name="ship" value="<?php echo $ship; ?>" /></p>
<p><label>Circuit :</label><br />
<textarea cols="50" rows="5" name="travel"><?php echo $travel; ?></textarea></p>
<p><label> Date départ :</label><br />
<input type="text" name="departure" value="<?php echo $departure; ?>" /></p>
<p><label>Durée :</label><br />
<input type="text" name="duration" value="<?php echo $duration; ?>" /></p>
<p><label>Prix de départ :</label><br />
<input type="text" name="price" value="<?php echo $price; ?>" /></p>
<p><label>Détails et conditions :</label><br />
<textarea cols="50" rows="5" name="details"><?php echo $details; ?></textarea></p>
<?php
}
function cabins()
{
global $post;
$custom = get_post_custom($post->ID);
$cabin1 = $custom["cabin1"][0];
$cabin2 = $custom["cabin2"][0];
$cabin3 = $custom["cabin3"][0];
$cabin4 = $custom["cabin4"][0];
$cabin5 = $custom["cabin5"][0];
?>
<p><label>Cabine intérieure :</label><br />
<input type="text" name="cabin1" value="<?php echo $cabin1; ?>" /></p>
<p><label>Cabine vue sur mer :</label><br />
<input type="text" name="cabin2" value="<?php echo $cabin2; ?>" /></p>
<p><label>Cabine avec balcon :</label><br />
<input type="text" name="cabin3" value="<?php echo $cabin3; ?>" /></p>
<p><label>Cabine avec mini-suite :</label><br />
<input type="text" name="cabin4" value="<?php echo $cabin4; ?>" /></p>
<p><label>Cabine avec suite :</label><br />
<input type="text" name="cabin5" value="<?php echo $cabin5; ?>" /></p>
<?php
}
function save_details()
{
global $post;
update_post_meta($post->ID, "slogan", $_POST["slogan"]);
update_post_meta($post->ID, "theme", $_POST["theme"]);
update_post_meta($post->ID, "ship", $_POST["ship"]);
update_post_meta($post->ID, "travel", $_POST["travel"]);
update_post_meta($post->ID, "departure", $_POST["departure"]);
update_post_meta($post->ID, "duration", $_POST["duration"]);
update_post_meta($post->ID, "price", $_POST["price"]);
update_post_meta($post->ID, "details", $_POST["details"]);
update_post_meta($post->ID, "cabin1", $_POST["cabin1"]);
update_post_meta($post->ID, "cabin2", $_POST["cabin2"]);
update_post_meta($post->ID, "cabin3", $_POST["cabin3"]);
update_post_meta($post->ID, "cabin4", $_POST["cabin4"]);
update_post_meta($post->ID, "cabin5", $_POST["cabin5"]);
}
add_action('save_post', 'save_details');
}