Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator keesiemeijer

    (@keesiemeijer)

    Try with something like this:

    <?php
    global $id;
    $mypages = get_pages('child_of='.$id);
    foreach ( $mypages as $mypage  ) {
    $attachments = get_children(array('post_parent' => $mypage->ID, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order'));
    if ( ! is_array($attachments) ) continue;
    $count = count($attachments);
    $first_attachment = array_shift($attachments);
    echo wp_get_attachment_image($first_attachment->ID);
    }
    ?>

    Thread Starter Richard Brown

    (@cregy)

    Thanks for the code but it isn’t showing anything!

    Do I need to insert anything in the code please?

    Thanks

    Moderator keesiemeijer

    (@keesiemeijer)

    try this: $mypages = get_pages('child_of='.$posts[0]->ID);
    or this: $mypages = get_pages('child_of=306');

    The images have to be attached to the Page (check gallery). You have to upload them when editing the page so they get attached to that Page otherwhise the images will not show because they are not an attachement of that Page.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Image from Sub Page’ is closed to new replies.