Get Alt for caption slider
Support › MB Builder › Get Alt for caption slider
- This topic has 4 replies, 2 voices, and was last updated 9 years, 5 months ago by
agenciaball.
-
AuthorPosts
-
October 23, 2015 at 7:37 PM #1607
agenciaball
Participanteae pessoal. Estou com um probleminha e gostaria de saber se existe essa possibilidade.
"Criei" um plugin com metabox com flexslider, e estou precisando pegar o alt ou titiulo da imagem para imprimir em um caption na image, observe o modo como eu chamo as imagens do campo:
<div class="flex-container-eventos"> <div class="flexslider"> <ul class="slides"> <?php global $wpdb; $images = get_post_meta( get_the_ID(), 'capa_evento', false ); $images = implode( ',' , $images ); // Re-arrange images with 'menu_order' $images = $wpdb->get_col( " SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND ID in ({$images}) ORDER BY menu_order ASC " ); foreach ( $images as $att ) { // Get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes $src = wp_get_attachment_image_src($att, 'large'); $src = $src[0]; // Show image echo "<li><img src='{$src}' /></li>"; } ?> </ul> </div>
October 23, 2015 at 10:06 PM #1608Anh Tran
KeymasterCan you please write in English?
October 23, 2015 at 10:38 PM #1611agenciaball
Participantwhat's up guys. I have a little problem and I wonder if there is such possibility.
"I created" a plugin with metabox with flexslider, and I need to catch the alt or image titiulo to print in a caption on the image, note how I call the images of the field:
<div class="flex-container-eventos"> <div class="flexslider"> <ul class="slides"> <?php global $wpdb; $images = get_post_meta( get_the_ID(), 'capa_evento', false ); $images = implode( ',' , $images ); // Re-arrange images with 'menu_order' $images = $wpdb->get_col( " SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND ID in ({$images}) ORDER BY menu_order ASC " ); foreach ( $images as $att ) { // Get image's source based on size, can be 'thumbnail', 'medium', 'large', 'full' or registed post thumbnails sizes $src = wp_get_attachment_image_src($att, 'large'); $src = $src[0]; // Show image echo "<li><img src='{$src}' /></li>"; } ?> </ul> </div>
October 25, 2015 at 8:32 AM #1614Anh Tran
KeymasterHi, you can simply use the helper function
rwmb_meta
to retrieve alt text of the image, like this:$images = rwmb_meta( 'capa_evento', 'type=image&size=large' ); foreach ( $images as $image ) { echo "<li><img src='{$image['url']}' alt='{$image['alt']}' /></li>"; }
Your code is outdated, it was in old code of Meta Box.
For more information about the helper function, please read the documentation here.
October 27, 2015 at 11:41 PM #1629agenciaball
ParticipantThanks, it's perfect!
-
AuthorPosts
- The topic ‘Get Alt for caption slider’ is closed to new replies.