Return to Snippet

Revision: 55577
at February 11, 2012 14:51 by shufflepath


Initial Code
// REALISATIONS
add_action('init', 'ajoute_une_realisation');
function ajoute_une_realisation(){
	$labels = array(
		'name' => _x('Ajouter une réalisation', 'taxonomy general name'),
		'singular_name' => _x('Ajouter une réalisation', 'taxonomy singular name'),
		'add_new' => _x('Ajouter une réalisation', 'realisation'),
		'add_new_item' => __('Ajouter une réalisation'),
		'edit_item' => __('Modifier une réalisation'),
		'new_item' => __('Ajouter une réalisation'),
		'view_item' => __('Voir une réalisation'),
		'search_items' => __('Rechercher une réalisation'),
		'not_found' =>  __('Aucune réalisation trouvée'),
		'not_found_in_trash' => __('Aucune réalisation trouvée'), 
		'parent_item_colon' => '',
		'menu_name' => 'Réalisations'
	);
	$args = array(
		'labels' => $labels,
		'public' => true,
		'publicly_queryable' => true,
		'show_ui' => true, 
		'show_in_menu' => true, 
		'menu_position' => 9,
		'query_var' => true,
		//'rewrite' => true,
		'rewrite' => array( 'slug' => 'realisations-et-clients' ),
		'capability_type' => 'page',
		'has_archive' => false, 
		'hierarchical' => false,
		//'taxonomies' => array('category'),
		'supports' => array('title','editor')
	); 
	register_post_type('realisations',$args);
	
}

add_filter("manage_edit-realisations_columns", "realisations_edit_columns");
add_action("manage_posts_custom_column",  "realisations_custom_columns");
add_filter("manage_edit-realisations_sortable_columns", "realisations_register_sortable" );

function realisations_edit_columns($columns){
		$columns = array(
			"cb" => "<input type=\"checkbox\" />",
			"activer_projet_sur_site" => "Actif sur le site",
			"est_un_projet_vedette" => "Projet vedette",
			"est_un_projet_branding" => "Projets Branding",
			"title" => "Titre du projet",
			"icl_translations" => $columns['icl_translations'],
			"date" => "Date"
		);

		return $columns;
}

function realisations_custom_columns($column){
		global $post;
		switch ($column)
		{
			case "activer_projet_sur_site":
				$custom = get_post_custom();
				if(get_field('acf_activer_le_projet_sur_le_site'))
				{
					echo 'Oui';
				}
				else
				{
					echo 'Non';
				}
				break;		
				
			case "est_un_projet_vedette":
				$custom = get_post_custom();
				if(get_field('acf_real_projet_en_vedette'))
				{
					echo 'Oui';
				}
				else
				{
					echo 'Non';
				}
				break;		
			case "est_un_projet_branding":
				$custom = get_post_custom();
				if(get_field('acf_est_un_projet_branding'))
				{
					echo 'Oui';
				}
				else
				{
					echo 'Non';
				}
				break;										
		}
}



function realisations_register_sortable($columns)
{
	$columns['activer_projet_sur_site'] = 'activer_projet_sur_site';
	$columns['est_un_projet_vedette'] = 'est_un_projet_vedette';
	$columns['est_un_projet_branding'] = 'est_un_projet_branding';
	return $columns;
}



//hook into the init action and call create_book_taxonomies when it fires
add_action( 'init', 'create_realisations_taxonomies', 0 );

//create two taxonomies, genres and writers for the post type "book"
function create_realisations_taxonomies() 
{
  // Add new taxonomy
  $labels = array(
    'name' => _x( 'Type de r&eacute;alisations', 'taxonomy general name' ),
    'singular_name' => _x( 'Type de r&eacute;alisation', 'taxonomy singular name' ),
    'search_items' =>  __( 'Rechercher un type' ),
    'all_items' => __( 'Tous les types' ),
    'parent_item' => __( 'Parent Types' ),
    'parent_item_colon' => __( 'Parent Types:' ),
    'edit_item' => __( 'Modifier un type' ), 
    'update_item' => __( 'Mise &agrave; jour du type' ),
    'add_new_item' => __( 'Ajouter un type' ),
    'new_item_name' => __( 'Nouveau nom du type' ),
    'menu_name' => __( 'Type de r&eacute;alisations' ),
  ); 	

  register_taxonomy('type_realisation',array('realisations'), array(
    'hierarchical' => true,
    'labels' => $labels,
    'show_ui' => true,
    'query_var' => true
  ));

}

/*
 * Example code showing how to hook WordPress to add fields to the taxonomny term edit screen.
 * 
 * This example is meant to show how, not to be a drop in example.
 *
 * This example was written in response to this question:
 *
 *    http://lists.automattic.com/pipermail/wp-hackers/2010-August/033671.html
 *
 * By:
 *
 *    Mike Schinkel (http://mikeschinkel.com/custom-wordpress-plugins/)
 *
 * NOTE:
 *
 *    This could easily become a plugin if it were fleshed out.
 *    A class with static methods was used to minimize the variables & functions added to the global namespace.
 *    wp_options was uses with one option be tax/term instead of via a serialize array because it aids in retrival
 *    if there get to be a large number of tax/terms types. A taxonomy/term meta would be the prefered but WordPress
 *    does not have one.
 *
 * This example is licensed GPLv2.
 *
 */
/*

// These are helper functions you can use elsewhere to access this info
function get_taxonomy_term_type($taxonomy,$term_id) {
  return get_option("_term_type_{$taxonomy}_{$term->term_id}");
}
function update_taxonomy_term_type($taxonomy,$term_id,$value) {
  update_option("_term_type_{$taxonomy}_{$term_id}",$value);
}

//This initializes the class.
TaxonomyTermTypes::on_load();

//This should be called in your own code. This example uses two taxonomies: 'region' & 'opportunity'
TaxonomyTermTypes::register_taxonomy(array('type_realisation'));

class TaxonomyTermTypes {
  //This initializes the hooks to allow saving of the
  static function on_load() {
    add_action('created_term',array(__CLASS__,'term_type_update'),10,3);
    add_action('edit_term',array(__CLASS__,'term_type_update'),10,3);
  }
  //This initializes the hooks to allow adding the dropdown to the form fields
  static function register_taxonomy($taxonomy) {
    if (!is_array($taxonomy))
      $taxonomy = array($taxonomy);
    foreach($taxonomy as $tax_name) {
      add_action("{$tax_name}_add_form_fields",array(__CLASS__,"add_form_fields"));
      add_action("{$tax_name}_edit_form_fields",array(__CLASS__,"edit_form_fields"),10,2);
    }
  }
  // This displays the selections. Edit it to retrieve
  static function add_form_fields($taxonomy) {
    echo "Services associ&eacute;s " . self::get_select_html('strategie');
  }
  // This displays the selections. Edit it to retrieve your own terms however you retrieve them.
  static function get_select_html($selected) {
    $selected_attr = array('strategie'=>'','developpement-web'=>'');
    $selected_attr[$selected] = ' selected="selected"';
    $html =<<<HTML
<select id="tag-type" name="tag-type">
  <option value="strategie"{$selected_attr['strategie']}>Strat&eacute;gie</option>
  <option value="developpement-web"{$selected_attr['developpement-web']}>D&eacute;veloppement Web</option>
</select>
HTML;
    return $html;
  }
    // This a table row with the drop down for an edit screen
    static function edit_form_fields($term, $taxonomy) {
    $selected = get_option("_term_type_{$taxonomy}_{$term->term_id}");
    $select = self::get_select_html($selected);
    $html =<<<HTML
<tr class="form-field form-required">
  <th scope="row" valign="top"><label for="tag-type">Services associ&eacute;s </label></th>
  <td>$select</td>
</tr>
HTML;
    echo $html;
  }
  // These hooks are called after adding and editing to save $_POST['tag-term']
  static function term_type_update($term_id, $tt_id, $taxonomy) {
	$varService = $_POST['tag-type'];
	if (isset($varService)) {
      update_taxonomy_term_type($taxonomy,$term_id,$varService);
	  
    }
  }
}
*/
add_filter("manage_edit-type_realisation_columns", 'type_realisation_columns');   
//add_action("manage_posts_custom_column",  "type_realisation_custom_columns");

   function type_realisation_columns($type_realisation_columns) {
    $new_columns = array(
        'cb' => '<input type="checkbox" />',
        'name' => __('Name'), 
        'description' => "Services associ&eacute;s", /* Solution broche � foin en attendant de trouver autre chose */ 
        'slug' => __('Slug'),
        'posts' => __('Posts')
        );
    return $new_columns;
   }

/*
function type_realisation_custom_columns($new_columns){
		global $post;
		switch ($new_columns) 
		{
			  case "services_associes":
   			  //$new_columns = get_post_custom();
			  echo("test");
			  break;
		  }
  
}
*/
/*
add_filter("manage_edit-type_realisation_columns", "type_realisation_edit_columns");
add_action("manage_posts_custom_column",  "type_realisation_custom_columns");

function type_realisation_edit_columns($columns){
		$columns = array(
			"cb" => "<input type=\"checkbox\" />",
			'name' => __('Name'),
			'slug' => __('Slug'),
        	'posts' => __('Posts'),
			"services_associes" => "Services associ&eacute;s"
		);

		return $columns;
}

function type_realisation_custom_columns($column){
		global $Post;
		
		switch ($column) {
			case "services_associes":
   			  $custom = get_post_custom();
			  echo "test";
			  break;
		  }
  
}

*/

Initial URL


Initial Description


Initial Title
Custom Post Type and Taxonomies

Initial Tags
php, wordpress

Initial Language
PHP