WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to know how to display all images from the current page siblings.

for eg. I got two parents (Hockey and football) with children. In all this children I got one or several images attached (I've simply uploaded them through wordpress deafult uploader). Now I want a page (called "All images from all teams" ) that display all images that are attached to their siblings / has the same parent as current. AND if you click on let say a images taken from the "New York Rangers" page, you will be sent to that page.


  • Detroit Red Wings
  • Toronto Maple Leafs
  • New York Rangers
  • All images from all hockey teams


  • Liverpool
  • Arsenal
  • Manchester United
  • All images from all football teams

Help! Please!

My code:

<?php get_header(); ?>   <?php if (have_posts()) : ?>   <?php while (have_posts()) : the_post(); ?>  <div class="big-img"> <?php echo do_shortcode('[portfolio_slideshow size=full navpos=disable trans=scrollHorz pagerstyle=bullets autoplay=true]'); ?> </div>     <div class="post-content"> <div class="left-nav">  <?php include "left-sidebar.php";?>  </div>  <div class="content">  <div class="post-title"> <h1><?php the_title(); ?></h1></div>  <?php the_content('read the entry &#187;'); ?> <?php the_tags( '<div class="main-meta"> Tags: ', ', ', '</div>'); ?> <?php echo do_shortcode('[portfolio_slideshow size=thumbnail carousel=false navpos=disable ]'); ?>  <div class="clear"></div> </div>   <?php endwhile; ?>  <?php next_posts_link('&laquo; old Posts') ?> <?php previous_posts_link('new Posts &raquo;') ?>  <?php else : ?>  Not Found  <?php include (TEMPLATEPATH . "/searchform.php"); ?>   <?php endif; ?>  </div>  </div>  <div class="right-nav">  <?php include "right-sidebar.php";?>  </div>  <?php include "footer.php";?>
share|improve this question
Can you post the code that you already have, or where you are stuck on exactly? Am I right that you need a function where you retrieve the attachmentchildren of the pages that have the same parentpage as the current one? – fischi Feb 26 '13 at 10:27

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:

  1. Loop through top level pages
  2. Collect child pages as array
  3. Loop through child pages
  4. Loop through child attachments

    Template Name: All images
    // 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'
                    ) ),
    // 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>';

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.

share|improve this answer
Thank you so much, i'll try your code asap! YNWA – Andy-with-love Feb 26 '13 at 13:00
If you want to display the portfolio slideshow thing for each team you can use the do_shortcode() snippets from your code in the teams loop rather than looping over the images. I'm assuming the shortcode will loop through the images for you – sanchothefat Feb 26 '13 at 14:10

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.