【发布时间】:2016-08-05 16:24:07
【问题描述】:
我正在 wordpress 上创建一个新页面并使用 php 代码添加图像。
这是我到目前为止的代码,它为我提供了数组中的 src url。但是我认为这给了我画廊中的所有图像。有没有办法只找到页面上的图像,然后将这些图像添加到页面中。请参阅下面的当前代码。
<?php
$query_images_args = array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'post_status' => 'inherit',
'posts_per_page' => - 1,
);
$query_images = new WP_Query( $query_images_args );
$images = array();
foreach ( $query_images->posts as $image ) {
echo wp_get_attachment_url( $image->ID );
}
?>
【问题讨论】: