[英]add images to html in wordpress from 'Page'
我正在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 );
}
?>
尝试这个
echo "<img src='".wp_get_attachment_url( $image->ID )."' />";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.