Last active
August 29, 2015 13:56
-
-
Save certainlyakey/9324016 to your computer and use it in GitHub Desktop.
Wordpress - custom gallery from WP post gallery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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