Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have this problem and maybe you can help me. I want to get a list of all children pages from page (with id 20) and then get the featured image from each one and resize with Thumbnail. Right now I get the_title from each one but not the Image so think there is a source problem. here's the code:

    <?php $args = array (
                    'child_of'     => 20,
                    'title_li'     => '',
                    'depth'         => 0,
                    'sort_order'    => 'DESC',
                    'sort_column'   => 'menu_order'
                    );

                    $pages = get_pages( $args );
                    foreach($pages as $page)  :
    setup_postdata($post);

    $src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), false, '' ); 
    $thumbnailSrc = $src[0];    
    ?>
    <li id="<?php echo $page->post_name; ?>">
    <h2><a href="<?php echo get_page_link($page->ID) ?>"><?php echo $page->post_title ?></a></h2>
    <img src="<?php bloginfo('template_directory'); ?>/scripts/timthumb.php?src=<?php echo $thumbnailSrc; ?>&h=256&w=415&zc=1q=100" />
    <?php endforeach; ?>
    </li>
share|improve this question
    
why do you want to resize the image instead of making a default thumb size? that way you can create a single loop why a query that will achieve your results... let me know your reason so I'll see if I can help u –  andresmijares25 Nov 23 '11 at 4:55
    
Thanks for your reply. As this is used on a template file which is no parent page from page id 20 I get nothing from <?php echo $thumbnailSrc; ?> What I want is to get the resized images from page with id 20. –  aurrutia Nov 23 '11 at 5:04
add comment

1 Answer

up vote 0 down vote accepted

Never mind about my question... here is your answer

Put this function on your functions.php

 // Get Featured Image Path
 function get_featured_image_link($size){
  global $post;
  $get_featured_image_link = get_the_post_thumbnail($post->ID, $size);
  preg_match("/(?<=src=['|\"])[^'|\"]*?(?=['|\"])/i", $get_featured_image_link, $thePath);
  return $get_featured_image_link_final = $thePath[0];
 }

Then this is the process to get the image...

 <?php
  $the_query = new  WP_Query( 
      array(
          'post_parent' => '20',
          'post_type' => 'page',
          'sort_column'   => 'menu_order'
      )
  ); ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    <li id="<?php echo $page->post_name; ?>">
     <h2><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
     <img src="<?php echo get_featured_image_link('Path'); ?>">
   </li> 
 <?php endwhile; ?>
<?php wp_reset_query() ?>

Set the width and height to whatever you want to...

Tested and worked!

Have fun!

share|improve this answer
    
hooooowever...I still don't know why you want to resize it instead of defining a specific thumbnail size and call it with the <?php the_thumbnail('YOURCUSTOMSIZE') ?> function :)! –  andresmijares25 Nov 23 '11 at 5:21
    
Wow! this works great! Reagrding the_thumbnail: Never managed to make it work as wanted, always have some issues with landscape and vertical format images, never crop the same size. Thanks for your help! –  aurrutia Nov 23 '11 at 6:07
add comment

Your Answer

 
discard

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.