有人知道如何在帖子中从wordpress gallery获取图像的ID吗?我已经在整个互联网上搜索过了,这个主题没有任何内容。
ID of images from gallery
2 个回复
SO网友:shea
通过切换到,您可以找到库中包含哪些图像的IDText “编辑器”选项卡并查找如下代码:
[gallery columns="3" link="file" ids="615,619,618,617,616"]
以逗号分隔的图像ID列表包含在ids
属性如果要查找现有图像的ID以手动创建图库,可以访问媒体库管理菜单,然后单击Edit 链接到图像下。在浏览器的地址栏中,您应该会看到类似以下内容:
http://example.com/wp-admin/post.php?post=622&action=edit
后面的数字post=
是图像ID。在这种情况下,图像ID是622
.SO网友:Mark Barnes
假设bungeshea是正确的,并且您希望使用PHP检索附加到图库的图像的ID,那么您可以过滤\'shortcode_atts_gallery\'
, 像这样:
add_filter (\'shortcode_atts_gallery\', \'wsec_filter_gallery_atts\', 10, 3);
function wpsec_filter_gallery_atts ($out, $pairs, $atts) {
$ids = $out[\'include\'];
// Do what you want with the ids
return $out;
}
结束