Created
December 24, 2014 15:40
-
-
Save davidperezgar/8842d6a4ade0d8edad97 to your computer and use it in GitHub Desktop.
CPT Con Jerarquía
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Custom Post Types Mobiliario | |
* | |
*/ | |
add_action('init', 'my_custom_init_mob'); | |
function my_custom_init_mob() | |
{ | |
if(WPLANG == 'es_ES') $slug = 'mobiliario-farmacias'; | |
if(WPLANG == 'it_IT') $slug = 'arredamento-farmacie'; | |
if(WPLANG == 'en_US') $slug = 'pharmacy-furniture'; | |
if(WPLANG == 'fr_FR') $slug = 'mobilier-pharmacies'; | |
$labels = array( | |
'name' => __('Product', 'clmkg'), | |
'singular_name' => __('Product', 'clmkg'), | |
'add_new' => __('Add Product', 'clmkg'), | |
'add_new_item' => __('Add New Product','clmkg'), | |
'edit_item' => __('Edit Product', 'clmkg'), | |
'new_item' => __('New Product', 'clmkg'), | |
'view_item' => __('View Product','clmkg'), | |
'search_items' => __('Search Products','clmkg'), | |
'not_found' => __('We did not find any products...'), | |
'not_found_in_trash' => __('We did not find any products in the trash...'), | |
'parent_item_colon' => '' | |
); | |
$args = array( | |
'labels' => $labels, | |
'public' => true, | |
'publicly_queryable' => true, | |
'show_ui' => true, | |
'query_var' => true, | |
'rewrite' => array( | |
'slug' => $slug, | |
'with_front' => true | |
), | |
'has_archive' => false, | |
'capability_type' => 'page', | |
'hierarchical' => true, | |
'menu_position' => 5, | |
'supports' => array('title','editor','thumbnail','excerpt','page-attributes') | |
); | |
register_post_type('mobiliario-farmacias',$args); | |
} | |
//Variable Meta para Mobiliario | |
add_action("admin_init", "admin_init_mobiliario"); | |
add_action('save_post', 'save_mobiliario'); | |
function admin_init_mobiliario(){ | |
add_meta_box("fichadele", "Variables Mobiliario", "meta_options_mobopt", "mobiliario-opticas", "side", "high"); | |
} | |
function meta_options_mobopt(){ | |
global $post; | |
$custom = get_post_custom($post->ID); | |
$mob_tipopag = $custom["mob_tipopag"][0]; | |
$mob_idgaleria = $custom["mob_idgaleria"][0]; | |
$mob_material1 = $custom["mob_material1"][0]; | |
$mob_material2 = $custom["mob_material2"][0]; | |
$mob_material3 = $custom["mob_material3"][0]; | |
$mob_material4 = $custom["mob_material4"][0]; | |
$mob_material5 = $custom["mob_material5"][0]; | |
?> | |
<p>Materiales Fabricación:</p> | |
<input name="mob_material1" value="<?php echo $mob_material1; ?>" class="widefat" style="width:87%;"/> | |
<input name="mob_material2" value="<?php echo $mob_material2; ?>" class="widefat" style="width:87%;"/> | |
<input name="mob_material3" value="<?php echo $mob_material3; ?>" class="widefat" style="width:87%;"/> | |
<input name="mob_material4" value="<?php echo $mob_material4; ?>" class="widefat" style="width:87%;"/> | |
<input name="mob_material5" value="<?php echo $mob_material5; ?>" class="widefat" style="width:87%;"/> | |
<?php | |
global $wpdb; | |
define("GALLERY_TABLE", $wpdb->prefix . "ngg_gallery"); | |
$idgalerias = $wpdb->get_results("SELECT * FROM " . GALLERY_TABLE); | |
echo '<p>Galería asociada:</p><select name="mob_idgaleria" style="width:97%;" value="'.$mob_idgaleria.'">'; | |
echo '<option value=""'; | |
if (!$mob_idgaleria) {echo ' selected="selected"';} | |
echo '></option>'; | |
foreach ($idgalerias as $category) { | |
$category_name = $category->title; | |
$category_identifier = $category -> gid; | |
echo '<option value="'.$category_identifier.'"'; | |
if ($mob_idgaleria==$category_identifier) {echo ' selected="selected"';} | |
echo '>'.$category_identifier.' - '.$category_name.'</option>'; | |
} | |
echo '</select>'; | |
?> | |
<p>Tipo de página:</p> | |
<select name="mob_tipopag" style="width:97%;" value="'.$mob_tipopag.'">'; | |
<option value="presentacion" <?php if ($mob_tipopag=='presentacion') {echo ' selected="selected"';} ?> | |
>Presentacion</option> | |
<option value="producto" <?php if ($mob_tipopag=='producto') {echo ' selected="selected"';} ?> | |
>Producto</option> | |
<option value="pagina" <?php if ($mob_tipopag=='pagina') {echo ' selected="selected"';} ?> | |
>Página</option> | |
</select> | |
<?php } | |
function save_mobiliario(){ | |
global $post; | |
$fields = array ('mob_tipopag','mob_idgaleria','mob_material1','mob_material2','mob_material3','mob_material4','mob_material5'); | |
foreach ($fields as $field) | |
if(isset($_POST[$field]) && $_POST[$field] != "") | |
update_post_meta($post->ID, $field, $_POST[$field]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment