Skip to content

Instantly share code, notes, and snippets.

@yratof
Created May 13, 2014 23:28
Show Gist options
  • Save yratof/1dcfd9e69b18dd294d8b to your computer and use it in GitHub Desktop.
Save yratof/1dcfd9e69b18dd294d8b to your computer and use it in GitHub Desktop.
Get the posts' attachments
<?php $args = array(
'post_type' => 'attachment',
'numberposts' => 1,
'orderby' => 'rand',
'post_status' => null,
'post_parent' => get_the_ID(),
'post_mime_type' => 'image'
);
$images = get_children( $args );
if ($images) {
foreach ( $images as $attachment_id => $attachment ) { ?>
<div class="relative">
<?php echo wp_get_attachment_image( $attachment_id, 'large' ); ?>
<div class="overlay">
<h2><?php echo apply_filters( 'the_title', $attachment->post_title ); // Image Title ?></h2>
<h3><?php echo get_the_title(); // Designer ?></h3>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment