我尝试了这段代码从媒体库获取所有图像,我成功地获取了所有图像的源URL,但现在我想排除所有不需要的图像,如徽标、标题图像等。。。
简而言之,我想提取贴在帖子和页面上的所有图像。。
if(is_single() || is_page() || is_home() ){
global $post;
$query_images_args = array(
\'post_type\' => \'attachment\', \'post_mime_type\' =>\'image\', \'post_status\' => \'inherit\', \'posts_per_page\' => -1,\'numberposts\' => 1
);
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image) {
$images[]= wp_get_attachment_url( $image->ID );
}
echo "<pre>";
print_r($images);
echo "</pre>";
我在这里的输出第一个图像是我不需要的标题图像。。如何排除。。我尝试过使用附件大小,但它不可能总是唯一的。。看看吧
Array
(
[0] => http://localhost/wordpress/wp-content/uploads/2013/03/AboutUsSlider.jpg
[1] => http://localhost/wordpress/wp-content/uploads/2013/03/7325996116_9995f40082_n.jpg
[2] => http://localhost/wordpress/wp-content/uploads/2013/03/6310273151_31b2d7bebe.jpg
[3] => http://localhost/wordpress/wp-content/uploads/2013/03/4764924205_ce7470f15a.jpg
[4] => http://localhost/wordpress/wp-content/uploads/2013/03/2166105529_70dd50ef4b_n.jpg
[5] => http://localhost/wordpress/wp-content/uploads/2013/03/1494822863_aca097ada7.jpg
[6] => http://localhost/wordpress/wp-content/uploads/2013/03/1385429771_453bc19702.jpg
)