我可以吗;附上;将图像添加到帖子而不将其添加到帖子
这背后的原因是,我可以使用API以任何方式操作它。
我可以将图片附加到帖子而不将其添加到帖子中吗?
3 个回复
最合适的回答,由SO网友:Horttcore 整理而成
有一个叫做附件的插件http://wordpress.org/extend/plugins/attachments/也许这就是你要找的东西。
SO网友:gillespieza
是的,这绝对是可能的:我在我的一个主题中这样做。
您只需将图像添加到帖子中,就好像您要将其插入帖子一样,但只需单击“保存所有更改”,而不是实际单击“插入帖子”按钮。
然后,您可以使用以下内容访问该帖子的图库图像:
$images = get_gallery_images();
我在函数中定义了这个函数。php:// get all of the images attached to the current post
function get_gallery_images() {
global $post;
$photos = get_children( array(\'post_parent\' => $post->ID, \'post_status\' => \'inherit\', \'post_type\' => \'attachment\', \'post_mime_type\' => \'image\', \'order\' => \'ASC\', \'orderby\' => \'menu_order ID\') );
$galleryimages = array();
if ($photos) {
foreach ($photos as $photo) {
// get the correct image html for the selected size
$galleryimages[] = wp_get_attachment_url($photo->ID);
}
}
return $galleryimages;
}
然后对模板文件中的图像执行任何操作。(在我的例子中,我循环浏览图像并将它们放在jQuery滑块中)。也有你可以使用的插件,但如果你能帮助的话,最好尽量减少插件。
SO网友:goldenapples
是的,你可以。
如果您使用帖子编辑屏幕上的媒体上传器上传图像,或使用update_post() 设定post_parent
要附加到的帖子ID的附件字段,它与该帖子关联,无论它是否实际插入到该帖子的内容中。
您可以通过调用get_children()
(see the codex for examples).
结束