Get Alt for caption slider

Support MB Builder Get Alt for caption slider

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1607
    agenciaballagenciaball
    Participant

    eae 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>
    #1608
    Anh TranAnh Tran
    Keymaster

    Can you please write in English?

    #1611
    agenciaballagenciaball
    Participant

    what'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>
    #1614
    Anh TranAnh Tran
    Keymaster

    Hi, 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.

    #1629
    agenciaballagenciaball
    Participant

    Thanks, it's perfect!

Viewing 5 posts - 1 through 5 (of 5 total)
  • The topic ‘Get Alt for caption slider’ is closed to new replies.