Skip to content

Instantly share code, notes, and snippets.

@gregoirenoyelle
Created March 3, 2012 13:05
Show Gist options
  • Save gregoirenoyelle/1965968 to your computer and use it in GitHub Desktop.
Save gregoirenoyelle/1965968 to your computer and use it in GitHub Desktop.
Treow Custom Post Type display
<?php
require_once(TEMPLATEPATH.'/lib/init.php');
include_once 'metaboxes/setup.php';
// META BOXEX WP ALCHEMY
// wpalchemy metadonnees
$gn_metadonnees_mb = new WPAlchemy_MetaBox(array
(
'id' => '_custom_metadonnees', // = références
'title' => 'Références',
'template' => get_stylesheet_directory() . '/metaboxes/gn-metadonnees-meta.php',
'types' => array('posttype_figure','posttype_corporation','posttype_pratique','posttype_production','posttype_ressource'),
'priority' => 'high',
'context' => 'normal',
'autosave'=> TRUE,
'lock' => WPALCHEMY_LOCK_AFTER_POST_TITLE
));
// wpalchemy liens
$gn_liens_extras_mb = new WPAlchemy_MetaBox(array
(
'id' => '_custom_liens',
'title' => 'Liens et Extras',
'template' => get_stylesheet_directory() . '/metaboxes/gn-metadonnees-liens.php',
'types' => array('posttype_figure','posttype_corporation','posttype_pratique','posttype_production','posttype_ressource'),
'priority' => 'high',
'context' => 'normal',
'autosave'=> TRUE,
'lock' => WPALCHEMY_LOCK_AFTER_POST_TITLE
));
<div class="my_meta_control">
<div class="child_meta_control">
<h4>Sur la toile</h4>
<?php while($metabox->have_fields_and_multi('toile')): ?>
<?php $metabox->the_group_open(); ?>
<?php $mb->the_field('toile_titre'); ?>
<p>
<label>Titre du lien</label>
<input type="text" name="<?php $metabox->the_name(); ?>" value="<?php $metabox->the_value(); ?>"/>
</p>
<?php $mb->the_field('toile_url'); ?>
<p>
<label>URL<span> (url complète)</span></label>
<input type="text" name="<?php $metabox->the_name(); ?>" value="<?php $metabox->the_value(); ?>"/>
</p>
<?php $mb->the_field('toile_description'); ?>
<p>
<label>Description du lien</label>
<input type="text" name="<?php $metabox->the_name(); ?>" value="<?php $metabox->the_value(); ?>"/>
</p>
<?php $selected = ' selected="selected"'; ?>
<p>
<label>Ouverture du lien <span>("_blank" = ouvrir le lien dans une nouvelle fenêtre)</span></label>
<?php $metabox->the_field('target'); ?>
<select name="<?php $metabox->the_name(); ?>">
<option value="">--</option>
<option value="_blank"<?php if ($metabox->get_the_value() == '_blank') echo $selected; ?>>_blank</option>
</select>
</p>
<p>
<label>Résumé sur le contenu</label>
<?php $mb->the_field('toile_resume'); ?>
<textarea name="<?php $mb->the_name(); ?>" rows="3"><?php $mb->the_value(); ?></textarea>
</p>
<a href="#" class="dodelete button">Supprimer le lien</a>
<?php $metabox->the_group_close(); ?>
<?php endwhile; ?>
<p style="margin-bottom:15px; padding-top:5px;"><a href="#" class="docopy-toile button">Ajouter un lien</a></p>
<input type="submit" class="button-primary" name="save" value="Sauvegarder">
</div><!-- / .child_meta_control -->
<div class="child_meta_control">
<h4>Vidéos</h4>
<?php while($metabox->have_fields_and_multi('video')): ?>
<?php $metabox->the_group_open(); ?>
<?php $mb->the_field('video_titre'); ?>
<p>
<label>Titre de la video</label>
<input type="text" name="<?php $metabox->the_name(); ?>" value="<?php $metabox->the_value(); ?>"/>
</p>
<p>
<label>Code embed</label>
<?php $mb->the_field('video_embed'); ?>
<textarea name="<?php $metabox->the_name(); ?>" rows="3"><?php $metabox->the_value(); ?></textarea>
</p>
<p>
<label>Résumé de la vidéo</label>
<?php $mb->the_field('video_resume'); ?>
<textarea name="<?php $metabox->the_name(); ?>" rows="4"><?php $metabox->the_value(); ?></textarea>
</p>
<a href="#" class="dodelete button">Supprimer la vidéo</a>
<?php $metabox->the_group_close(); ?>
<?php endwhile; ?>
<p style="margin-bottom:15px; padding-top:5px;"><a href="#" class="docopy-video button">Ajouter une vidéo</a></p>
<input type="submit" class="button-primary" name="save" value="Sauvegarder">
</div><!-- / .child_meta_control -->
<div class="child_meta_control last">
<h4>Extras</h4>
<p>
<label>Bloc Note</label>
<?php $mb->the_field('bloc_note'); ?>
<textarea name="<?php $metabox->the_name(); ?>" rows="5"><?php $metabox->the_value(); ?></textarea>
</p>
</div><!-- / .child_meta_control -->
</div><!-- / .my_meta_control -->
<style type"text/css">
#wpa_loop-toile .wpa_group,
#wpa_loop-video .wpa_group {
border: 1px solid #DFDFDF;
padding: 10px;
margin: 10px 0px;
background-color: #fff;
}
</style>
<script type="text/javascript">
// rendre les boîte "sortable". Attention: en agissant sur le parent
//<![CDATA[
jQuery(function($) {
$('#wpa_loop-toile, #wpa_loop-video').sortable();
});
//]]>
</script>
<div class="my_meta_control">
<h4>Références (twitter, Site, A propos...)</h4>
<?php while($metabox->have_fields_and_multi('references')): ?>
<?php $metabox->the_group_open(); ?>
<?php $mb->the_field('type_reference'); ?>
<p>
<label>Type de référence</label>
<input type="text" name="<?php $metabox->the_name(); ?>" value="<?php $metabox->the_value(); ?>"/>
</p>
<?php $mb->the_field('lien_titre'); ?>
<p>
<label>Titre du lien</label>
<input type="text" name="<?php $metabox->the_name(); ?>" value="<?php $metabox->the_value(); ?>"/>
</p>
<?php $mb->the_field('lien_url'); ?>
<p>
<label>URL<span> (url complète)</span></label>
<input type="text" name="<?php $metabox->the_name(); ?>" value="<?php $metabox->the_value(); ?>"/>
</p>
<?php $mb->the_field('lien_description'); ?>
<p>
<label>Description du lien</label>
<input type="text" name="<?php $metabox->the_name(); ?>" value="<?php $metabox->the_value(); ?>"/>
</p>
<?php $selected = ' selected="selected"'; ?>
<p>
<label>Ouverture du lien <span>("_blank" = ouvrir le lien dans une nouvelle fenêtre)</span></label>
<?php $metabox->the_field('target'); ?>
<select name="<?php $metabox->the_name(); ?>">
<option value="">--</option>
<option value="_blank"<?php if ($metabox->get_the_value() == '_blank') echo $selected; ?>>_blank</option>
</select>
</p>
<a href="#" class="dodelete button">Supprimer la référence</a>
<?php $metabox->the_group_close(); ?>
<?php endwhile; ?>
<p style="margin-bottom:15px; padding-top:5px;"><a href="#" class="docopy-references button">Ajouter une référence</a></p>
<input type="submit" class="button-primary" name="save" value="Sauvegarder">
</div><!-- / .my_meta_control -->
<style type"text/css">
#wpa_loop-references .wpa_group {
border: 1px solid #DFDFDF;
padding: 10px;
margin: 10px 0px;
background-color: #fff;
}
</style>
<script type="text/javascript">
// rendre les boîte "sortable". Attention: en agissant sur le parent
//<![CDATA[
jQuery(function($) {
$('#wpa_loop-references').sortable();
});
//]]>
</script>
<?php global $gn_liens_extras_mb; ?>
<div class="bloc-meta-media">
<h3 class="titre-extra titre-media">Sur la toile</h3>
<dl>
<?php while ( $gn_liens_extras_mb->have_fields('toile') ) : ?>
<dt><a href="<?php $gn_liens_extras_mb->the_value('toile_url'); ?>" <?php if ( $gn_liens_extras_mb->get_the_value('target') != '') : ?>target="<?php $gn_liens_extras_mb->the_value('target'); ?>"<?php endif; ?> title="<?php $gn_liens_extras_mb->the_value('toile_description'); ?>" ><?php $gn_liens_extras_mb->the_value('toile_titre'); ?></a></dt>
<dd><?php $gn_liens_extras_mb->the_value('toile_resume'); ?></dd>
<?php endwhile; ?>
</dl>
</div><!-- / .bloc-meta-media -->
<div class="bloc-meta-media video">
<h3 class="titre-extra titre-media">Vidéo</h3>
<div class="bloc-video">
<?php while ( $gn_liens_extras_mb->have_fields('video') ) : ?>
<h4><?php $gn_liens_extras_mb->the_value('video_titre'); ?></h4>
<div class="video-embed"><?php $gn_liens_extras_mb->the_value('video_embed'); ?></div>
<p class="video-resume"><?php $gn_liens_extras_mb->the_value('video_resume'); ?></p>
<?php endwhile; ?>
</div><!-- .bloc-video -->
</div><!-- / .bloc-meta-media -->
<?php global $gn_metadonnees_mb; ?>
<?php $gn_metadonnees_mb->the_meta();
// with this line it works!!
?>
<h3 class="titre-extra titre-meta">Métadonnées</h3>
<?php while ( $gn_metadonnees_mb->have_fields('references') ) : ?>
<p class="extra-field metadonnees meta-site"><span class="meta-titre"><?php $gn_metadonnees_mb->the_value('type_reference'); ?></span> <a href="<?php $gn_metadonnees_mb->the_value('lien_url'); ?>" <?php if ( $gn_metadonnees_mb->get_the_value('target') != '') : ?>target="<?php $gn_metadonnees_mb->the_value('target'); ?>"<?php endif; ?> title="<?php $gn_metadonnees_mb->the_value('lien_description'); ?>"><?php $gn_metadonnees_mb->the_value('lien_titre'); ?></a></p>
<?php endwhile; ?>
<?php
// Template Name: Pages Custom Post Type
/**************************
TODO
-20120106
- refaire boucle avec get_template_part (OK)
- 20120302
- wp alchemy ne s'affiche sauf le titre. Ai essayé sans get_template_part mais ne fonctionne pas. A voir (gnaction)
- 20120303
- modèle fonctionne avec la loop Genesis
- appel de page automatique
**************************/
add_action('genesis_before_loop','gn_content_page');
function gn_content_page(){
$gn_pagename = get_query_var('pagename');
$gn_quer_page = new WP_Query ('pagename='.$gn_pagename);
// début loop $gn_quer_page
while ( $gn_quer_page->have_posts() ) : $gn_quer_page->the_post(); ?>
<h1 class="entry-title cpt-title"><?php the_title(); ?></h1>
<div class="entry-content">
<?php the_content(); ?>
</div>
<?php endwhile;
wp_reset_postdata();
// fin loop $gn_quer_page
} ?>
<?php
// nouvelle boucle apres la page
remove_action('genesis_loop','genesis_do_loop');
add_action('genesis_loop','gn_loop_page');
function gn_loop_page() {
// Conditionnel sur page
if ( is_page('6') ) { // page figures
$gn_postype = 'posttype_figure';
} elseif ( is_page('34') ) { // page corporation
$gn_postype = 'posttype_corporation';
} elseif ( is_page('44') ) {
$gn_postype = 'posttype_pratique';
} elseif ( is_page('447') ) {
$gn_postype = 'posttype_production';
} else {}
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type' => $gn_postype,
'paged' => $paged,
'posts_per_page' => 3,
'orderby' => 'title',
'order' => 'ASC'
); // fin WP_Query
genesis_custom_loop( $args );
} // END function gn_loop_page()
remove_action('genesis_post_content', 'genesis_do_post_image');
remove_action('genesis_post_title', 'genesis_do_post_title');
remove_action('genesis_before_post_content', 'genesis_post_info');
remove_action('genesis_after_post_content', 'genesis_post_meta');
remove_action('genesis_post_content', 'genesis_do_post_content');
add_action('genesis_post_content','gn_genesis_do_post_content');
function gn_genesis_do_post_content(){ ?>
<div <?php post_class('post-archive-cpt'); ?>>
<?php if ( has_post_thumbnail() ) :
echo '<div class="bloc-thumbnail">';
echo '<a href="'. get_permalink() . '">';
the_post_thumbnail('Widget 150x150', array('class'=>'thumb-archives') );
echo '</a>';
echo '</div><!-- .bloc-thumbnail -->';
endif;
// teste si thumbnail ou non pour ajuster la largeur
if ( has_post_thumbnail() ) {
echo '<div class="bloc-meta-mini thumb-oui">';
} else {
echo '<div class="bloc-meta-mini thumb-non">';
}
echo '<h2 class="post-title"><a href="'. get_permalink(). '">' . get_the_title() . '</a></h2>';
get_template_part('meta','metadonnees');
echo '</div><!-- / .bloc-meta-mini -->';
echo '<br class="clear" />';
echo '<div class="bloc-avant-contenu"></div>';
echo '</div><!-- fin .post -->';
} // END function gn_genesis_do_post_content()
genesis();
<?php
/**************************
TODO:
-20120106
- afficher les taxo sous les metasdonnées
**************************/
add_action('genesis_before_loop','gn_conditionnel_single');
function gn_conditionnel_single() {
// conditionnel pour ne pas afficher les meta sur single normales
if ( 'posttype_figure' == get_post_type() || 'posttype_corporation' == get_post_type() || 'posttype_pratique' == get_post_type() || 'posttype_production' == get_post_type() || 'posttype_ressource' == get_post_type() ) :
add_action('genesis_post_content','gn_meta_avant_post', 5);
function gn_meta_avant_post() {
// teste si thumbnail ou non pour ajuster la largeur
if ( has_post_thumbnail() ) :
echo '<div class="bloc-thumbnail">';
echo '<a href="'. get_permalink() . '">';
the_post_thumbnail('Widget 300x300');
echo '</a>';
echo '</div><!-- .bloc-thumbnail -->';
endif;
// teste si thumbnail ou non pour ajuster la largeur
if ( has_post_thumbnail() ) {
echo '<div class="bloc-meta-mini thumb-oui">';
} else {
echo '<div class="bloc-meta-mini thumb-non">';
}
get_template_part('meta','metadonnees');
get_template_part('meta','taxo');
echo '</div><!-- / .bloc-meta-mini -->';
echo '<br class="clear" />';
echo '<div class="bloc-avant-contenu"></div>';
// test pour afficher le tableau des metas
/*
global $gn_metadonnees_mb;
$all_meta = $gn_metadonnees_mb->the_meta();
echo '<pre>';
print_r($all_meta);
echo '</pre>';
*/
}
add_action('genesis_post_content','gn_meta_apres_post',30);
function gn_meta_apres_post() {
get_template_part('meta','liens');
} // function gn_meta_apres_post()
endif; // END CONDITIONNEL 'posttype_figure' == get_post_type() ||....
} // fin function gn_conditionnel_single()
genesis();
@gregoirenoyelle
Copy link
Author

Hi Dimas, I fund the solution by adding $gn_metadonnees_mb->the_meta(); after global $gn_metadonnees_mb on the meta-metadonnees.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment