I'm a fan of page templates - Here's what I would do.
First create a page called something like Person Gallery
, call it whatever you'd like.
Then we can create either a separate template page-person-gallery.php
or open our page.php
and run a conditional in our loop to test if we're viewing the Person Gallery Page:
<?php if(have_posts()) : ?>
<?php while(have_posts()) : the_post(); ?>
<?php if($post->post_name == 'person-gallery') : /** Better to test for ID **/ ?>
<!-- We're on the Person Gallery Page -->
<?php else : ?>
<!-- Run default info -->
<?php endif; ?>
<?php endwhile; ?>
<?php endif; ?>
Either method you pick, we can now build a query based off what we know about about the person, which is nothing right now. We will need to build a link on your single.php
that can give us a bit more information about the person. So when you create your links to the person-gallery
we can pass our person ID. It'll look something like this:
<!-- Again, better getting permalink by ID -->
<a href="<?php echo get_permalink( get_page_by_path( 'person-gallery' ) ).'?person='.$post->ID ?>">View Gallery</a>
Now when somebody clicks that link, it will pass us that person ID which we can then base our query on. So let's create get our images:
<?php
if(isset($_GET['person']) && is_numeric($_GET['person'])) {
$pesonID = $_GET['person'];
$attachments = get_children(
array(
'numberposts' => -1,
'post_mime_type' => 'image',
'post_parent' => $personID,
'post_status' => 'any',
'post_type' => 'attachment'
)
);
/** Now we can display our images! **/
$attachments = get_children(
array(
'numberposts' => -1,
'post_mime_type' => 'image',
'post_parent' => $post->ID,
'post_status' => 'any',
'post_type' => 'attachment'
)
);
/** Now we can display our images! **/
foreach($attachments as $imgID => $img){
echo wp_get_attachment_image($imgID);
}
}
else{
echo "<p>No Images Found.</p>";
}
?>
You can pass some sizes and such to wp_get_attachment_image
, View The Codex to see what gets returned.