Skip to content

Instantly share code, notes, and snippets.

@gera3d
Created May 12, 2016 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gera3d/09389d744ad68e06fec66b10aadaab9f to your computer and use it in GitHub Desktop.
Save gera3d/09389d744ad68e06fec66b10aadaab9f to your computer and use it in GitHub Desktop.
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment