Skip to content

Instantly share code, notes, and snippets.

@RafaelFunchal
Last active February 2, 2016 11:43
Show Gist options
  • Save RafaelFunchal/5040724 to your computer and use it in GitHub Desktop.
Save RafaelFunchal/5040724 to your computer and use it in GitHub Desktop.
Show all post attachments
<?php
$attachment_args = array(
'post_type' => 'attachment',
'numberposts' => -1,
'post_status' => 'any',
'post_parent' => get_the_ID()
);
$attachments = get_posts( $attachment_args );
if ( $attachments ) {
$attachment_return = '<ul class="attachments">';
foreach ( $attachments as $attachment ) {
$attachment_src = wp_get_attachment_image_src( $attachment->ID, 'full' );
$attachment_return .= '<li>';
$attachment_return .= '<a rel="INSERT_YOUR_CLASS_HERE" href="'. $attachment_src[0] .'" title="'. apply_filters( 'the_title', $attachment->post_title ) .'">';
$attachment_return .= wp_get_attachment_image( $attachment->ID, 'thumbnail' );
$attachment_return .= '</a>';
$attachment_return .= '</li>';
}
$attachment_return .= '</ul>';
echo $attachment_return;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment