• I’m trying to get a array of pages under a particular parent page, and get the featured image for that page. I’m starting out with:

    <?php
    	$mypages = get_pages( array( 'child_of' => 94 ) );
    	foreach( $mypages as $page ) {
    		$content = $page->post_content;
    		if ( ! $content ) // Check for empty page
    			continue;
    		$content = apply_filters( 'the_content', $content );
                    $pageid = $page->ID;
    	?>
    		<article id="keypage-<?php echo $pageid; ?>">

    Then, I’ve tried to get the image for that page with (and variations of, by adding the page ID as an argument)

    <?php
                    if ( has_post_thumbnail() ) {
    	the_post_thumbnail();
    }
    else {
    	echo '<img src="' . get_bloginfo( 'stylesheet_directory' ) . '/images/thumbnail-default.jpg" />';
    }
    ?>

    This isn’t working. What I’m trying to get is the same “results” the post code returns, which code is below.

    <?php
    	$key_query = new WP_Query('category_name=key_posts&posts_per_page=8');
            while ($key_query->have_posts()) : $key_query->the_post();
    ?>
    <?php
    if ( has_post_thumbnail() ) { ?>
    	<a href="<?php the_permalink() ?>"><img class="scale-with-grid" src="<?php bloginfo('stylesheet_directory'); ?>/timthumb.php?src=<?php get_image_url(); ?>&h=164&w=592&zc=1" alt=""/></a>
    <?php } else { ?>
    	<a href="<?php the_permalink() ?>"><img class="scale-with-grid" src="<?php bloginfo('template_directory'); ?>/images/dummy.jpg" alt="" /></a>
    <?php } ?>

    Can someone show me how to do this?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How to get featured image for a page, not a post?’ is closed to new replies.