Using the below code I have successfully listed WordPress page titles. the pages have a Featured Image . when I run the below code the image shows up as the Image Unavailable
one instead of the actual correct image.
Have I missed something out? The Title displays correctly.
PHP
<?php query_posts(array('showposts' => 30, 'post_parent' => $post->ID, 'post_type' => 'page'));
while (have_posts()) { the_post();
if(has_post_thumbnail()) { ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail('medium');?>
</div>
<?php } else { ?>
<div class="entry-thumbnail">
<img src="/assets/dummy-image.jpg" alt="Image Unavailable" />
</div>
<?php } ?>
<?php the_title();
}
wp_reset_query(); // Restore global post data
}?>
has_post_thumbnail() sometimes fails as codex says here http://codex.wordpress.org/Function_Reference/has_post_thumbnail
can you try the following
if ( '' != get_the_post_thumbnail() ) { ?>
<div class="entry-thumbnail">
<?php the_post_thumbnail('medium');?>
</div>
<?php } else { ?>
<div class="entry-thumbnail">
<img src="/assets/dummy-image.jpg" alt="Image Unavailable" />
</div>
<?php } ?>
<?php $this_page_id=$wp_query->post->ID; ?>
<?php query_posts(array('showposts' => 20, 'post_parent' => $this_page_id, 'post_type' => 'page')); while (have_posts()) { the_post(); ?>
<?php $url = wp_get_attachment_url( get_post_thumbnail_id($this_page_id, 'thumbnail') ); ?>
<img src="<?php echo $url ?>" />
<h2><?php the_title(); ?></h2>
<?php } ?>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.