gera3d
5/12/2016 - 10:24 PM

Related images add alt

Related images add alt

<?php

/*
*  Loop through post objects (assuming this is a multi-select field) ( don't setup postdata )
*  Using this method, the $post object is never changed so all functions need a seccond parameter of the post ID in question.
*/?>
<div class="row">
    <div class="col-xs-12 related_videos secondary_color">
        <h2 class="clearboth">Related Videos</h2>
    </div>

</div>

<div class="row no-gutters">
    <?php $post_objects = get_field('testimonials_related');

    if( $post_objects ): ?>

        <?php foreach( $post_objects as $post_object): ?>

                <div class="col-xs-6 col-md-3 ">
                    <?php
                    // Still need to add alt text and titles to this image loop.
                    $video_id = get_post_meta( $post_object->ID, 'youtube_video_main', true );
                    $img = wp_get_attachment_image_src(get_post_thumbnail_id( $post_object->ID ), 'person-play');
                    $img_title = get_the_title($post_object->ID);
                    $alt = get_post_meta(get_post_thumbnail_id( $post_object->ID), '_wp_attachment_image_alt', true);?>
                    <a href="<?php echo get_permalink($post_object->ID); ?>" <?php echo "title='" . $img_title . "'"; ?>>
                        <img src="<?php echo $img[0] ; ?>" width="<?php echo $img[1] ?>" height="<?php echo $img[2] ?>" <?php echo "alt='" . $alt . "'" ?> <?php echo "title='" . $img_title . "'"; ?>/>
                    </a>
                </div>

        <?php endforeach; ?>

    <?php endif; ?>
</div>