使用 wordpress get_attached_media() 获取图像 [英] get images with wordpress get_attached_media()

查看:48
本文介绍了使用 wordpress get_attached_media() 获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

谁能告诉我如何使用 get_attached_media('img', postID);从帖子中获取所有附加的图像,然后显示图像?

Can somebody please tell me how I can use get_attached_media( 'img', postID ); to get all the attached images from the post and then display the images?

我需要跟随它的代码来获取图像.

I need the code that goes after it to get the images.

我直接在安装了 phpexec 插件的页面中使用此功能

I'm using this function directly within a page with phpexec plugin installed

提前致谢

推荐答案

get_attached_media 返回 WP_Post 类型数据

get_attached_media returns WP_Post type data

<?php 
$images = get_attached_media('image', $post->ID);
foreach($images as $image) { ?>
    <img src="<?php echo wp_get_attachment_image_src($image->ID,'full'); ?>" />
<?php } ?>

您可以根据标准尺寸或可能添加到主题function.php

you can replace the word 'full' with the size of the image you would like either based on the standard sizes or potentially ones you've added to your theme's function.php

如果您正在寻找图像"以外的项目,您应该使用 wp_get_attachment_url 而不是 wp_get_attachment_image_url

if you are looking for items other than 'image' you should use wp_get_attachment_url instead of wp_get_attachment_image_url

这篇关于使用 wordpress get_attached_media() 获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆