• Resolved maanse

    (@maanse)


    Hi guys,

    Im using the following code to show the featured image of a sub/child page within the parent page.

    <?php
    $child_pages = $wpdb->get_results("SELECT *    FROM $wpdb->posts WHERE post_parent = ".$post->ID."    AND post_type = 'page' ORDER BY menu_order", 'OBJECT');    ?>
    <?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
    <div class="child-thumb">
      <?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?>
     <a href="<?php echo  get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a>
    </div>
    <?php endforeach; endif;
    ?>

    Just wondered if any one can point out how to make the image a hyperlink to the sub page too, not just the title?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi,

    You could put :
    <?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?>
    in the link, like this :
    <a href="<?php echo get_permalink($pageChild->ID); ?>" rel="bookmark" title="<?php echo $pageChild->post_title; ?>"><?php echo get_the_post_thumbnail($pageChild->ID, 'thumbnail'); ?></a>
    Isn’t it ? Did I understand what you want to do ?

    Thread Starter maanse

    (@maanse)

    Yep understood perfectly, thanks.

    Just one more thing, any suggestions on how i can line the thumbnails up in rows of 3? I had initially thought of using floats but the problem is im going to have more than 3 thumbnails on most pages….

    Any suggestions?

    Yeah, Float will break all the content.
    You have to create a count function to display at least only 3 posts per row.

    Read this :
    Align Posts in a Row, aka Posts in Columns

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Featured image of child pages’ is closed to new replies.