我曾嘗試這個代碼從媒體庫中的所有圖像,我成功地讓所有的圖片的來源網址,但現在我要排除所有不需要的相似圖片的標誌,標題圖片等如何在Wordpress中提取不包括標題和徽標圖像的帖子和頁面的圖像?
總之我想提取附着的文章和網頁的所有圖片..
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>";
我的輸出 這裏的第一圖像爲標題圖片爲我..How這是不必要的,以排除它..我已經嘗試使用附件大小,但不能始終保持獨特..看看它吧
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
)