Nice to see Liverpool at the top there!
I’d go about this using a page template. Given that as far as I’m aware we only know the page names I’ll add it in that way.
The process is this:
- Loop through top level pages
- Collect child pages as array
- Loop through child pages
-
Loop through child attachments
<?php /* Template Name: All images */ get_header(); // pages to loop through $sports = array( 'Hockey', 'Football' ); // empty array where we collect teams $teams = array(); // collect teams foreach( $sports as $sport ) { $page = get_page_by_title( $sport ); $teams = array_merge( get_children( array( 'post_parent' => $page->ID, 'numberposts' => -1, 'post_type' => 'page' ) ), $teams ); } // you could do some custom sorting or randomisation of the order here // loop through teams foreach( $teams as &$team ) { // get image attachments for each team $images = get_children( array( 'post_parent' => $team->ID, 'numberposts' => -1, 'post_type' => 'attachment', 'post_mime_type' => 'image' ) ); // output images foreach( $image as &$image ) { // link to team page echo '<a href="' . get_permalink( $team->ID ) . '">'; echo wp_get_attachment_image( $image->ID, 'medium' ); echo '</a>'; } } get_sidebar(); get_footer();
You’ll want to modify the markup a bit and bear in mind this will be quite slow so you may want to consider a caching plugin.