你好!我正在寻找一种列出帖子媒体库中所有图像文件的方法。
我的意思是,如果在创建或编辑帖子时上载了文件,是以某种方式与该帖子相关联的文件,我是否可以从该数据中创建一个列表。
我认为next_image_link()/previous_image_link();模板标签与我所发现的非常接近。
我认为这应该很接近:
$query = 'SELECT * FROM `wp_posts`
WHERE `post_parent` = \''.$_GET['post_id'].'\'
AND `post_mime_type` = \'image/jpeg\'
ORDER BY `menu_order` ASC';
谢谢。
最佳答案
用wordpress术语来说,您上传到特定帖子的每个图像都称为附件。
要列出所有附件,可以使用get_children()函数:
$images =& get_children( 'post_type=attachment&post_mime_type=image&post_parent=10' );
$counter=0;
foreach( (array) $images as $attachment_id => $attachment )
{
$counter++;
echo "<a href='".wp_get_attachment_link( $attachment_id ) . "'>image $counter</a><br />";
}
该算法就是这样。
关于WordPress:查询帖子媒体库中的所有图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1369833/