以短代码的形式:
add_shortcode(\'nofeatures\', \'wpse_51768_shortcode\');
function wpse_51768_shortcode() {
$posts = get_posts( array(\'numberposts\' => -1) );
foreach ( $posts as $post ) {
$featured = get_the_post_thumbnail( $post->ID, \'thumbnail\', null );
if ( $featured ) echo \'Has Featured Image: \' . $post->post_title . \'<br />\';
}
}
[update]
以下输出了
don\'t have a Featured Image, 如果有,请检查文件是否
live:
add_shortcode(\'nofeatures\', \'shortcode_wpse_51768\');
function shortcode_wpse_51768()
{
$args = array(
\'numberposts\' => -1,
\'post_type\' => \'post\',
\'post_status\' => \'publish\'
);
$posts = get_posts( $args );
foreach ( $posts as $post )
{
$featured = has_post_thumbnail( $post->ID );
if ( !$featured )
echo "<p>Doesn\'t have Featured Image: <b>" . $post->post_title . "</b></p>";
else
{
$thumb = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), \'full\' );
$is_live = check_if_featured_image_is_live( $thumb[0] );
if ( !$is_live )
echo \'<p>Featured image 404: <b>\' . $post->post_title . \'</b></p>\';
}
}
}
// http://stackoverflow.com/a/7953100/1287812
function check_if_featured_image_is_live($url)
{
$options[\'http\'] = array(
\'method\' => "HEAD",
\'ignore_errors\' => 1,
\'max_redirects\' => 0
);
$body = file_get_contents($url, NULL, stream_context_create($options));
sscanf($http_response_header[0], \'HTTP/%*d.%*d %d\', $code);
return $code === 200;
}