Skip to content

Instantly share code, notes, and snippets.

@certainlyakey
Last active August 29, 2015 13:56
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 certainlyakey/9324016 to your computer and use it in GitHub Desktop.
Save certainlyakey/9324016 to your computer and use it in GitHub Desktop.
Wordpress - custom gallery from WP post gallery
<?php
$args = array(
'numberposts' => -1, // Using -1 loads all posts
'orderby' => 'menu_order', // This ensures images are in the order set in the page media manager
'order'=> 'ASC',
'post_mime_type' => 'image', // Make sure it doesn't pull other resources, like videos
'post_parent' => $post->ID, // Important part - ensures the associated images are loaded
'post_status' => null,
'post_type' => 'attachment'
);
$images = get_children( $args );
// Starkers_Utilities::print_a($images);
if ($images) { ?>
<ul class="gallery">
<?php foreach($images as $image){
$imgsrc = wp_get_attachment_image_src( $image->ID, 'medium');
// array_push($imgsrc, $imgsrcarr[0]);
?>
<li><figure class="gallery-item">
<img src="<?php echo $imgsrc[0]; ?>" alt="<?php echo $image->post_title; ?>" title="<?php echo $image->post_title; ?>">
</figure></li>
<?php } ?>
</ul>
<?php } ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment