Created
August 5, 2012 03:05
-
-
Save bgallagh3r/3261304 to your computer and use it in GitHub Desktop.
WordPress: Fetch image attachments from child pages.
This file contains 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 | |
global $post; | |
// Get All children of current page. | |
$children = get_pages(array('child_of' => $post->ID)); | |
// Increment value. | |
$i = 0; | |
foreach ($children as $child){ | |
// Get Image Source | |
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $child->ID ), 'thumbnail' ); | |
// Get Child Title to use as ALT | |
$title = get_the_title($child->ID); | |
// Check if image is even or odd class. | |
$class = $i % 2 == 0 ? "even" : "odd"; | |
// Echo image. | |
echo "<img src=\"$image\" alt=\"$title\" class=\"$class\">"; | |
$i++; | |
} | |
unset($i, $image, $title, $class); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment