Last active
February 5, 2017 20:07
-
-
Save everaldomatias/870830d8f795fc81c48cdf3230f2d446 to your computer and use it in GitHub Desktop.
Adiciona galeria de imagens (image_plupload) ao CPT Fotos.
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 | |
require_once get_template_directory() . '/core/classes/class-metabox.php'; | |
// Adiciona galeria de fotos com odin metabox | |
function gallery_metabox() { | |
$videos_metabox = new Odin_Metabox( | |
'fotos', // Slug/ID of the Metabox (Required) | |
'Galeria de Fotos', // Metabox name (Required) | |
'fotos', // Slug of Post Type (Optional) | |
'normal', // Context (options: normal, advanced, or side) (Optional) | |
'high' // Priority (options: high, core, default or low) (Optional) | |
); | |
$videos_metabox->set_fields( | |
array( | |
// Image Plupload field. | |
array( | |
'id' => 'fotos_plupload', // Required | |
'label' => __( 'Fotos', 'odin' ), // Required | |
'type' => 'image_plupload', // Required | |
// 'default' => '', // Optional (image attachment ids separated with comma) | |
'description' => __( 'Envie as fotos para a galeria de fotos', 'odin' ), // Optional | |
), | |
) | |
); | |
} | |
add_action( 'init', 'gallery_metabox', 1 ); | |
// Loop das imagens da galeria | |
$gallery = get_post_meta( $post->ID, 'fotos_plupload', true ); | |
$gallery = explode( ',', $gallery ); | |
$gallery = array_unique( $gallery ); | |
foreach ( $gallery as $image_id ) { | |
$image = wp_get_attachment_image_src( $image_id, 'thumbnail' ); | |
$image_full = wp_get_attachment_image_src( $image_id, 'full' ); | |
echo '<a class="" href="' . $image_full[0] . '">'; | |
echo '<img src="' . $image[0] . '">'; | |
echo '</a>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment