在 WordPress 项目开发中,也许我们需要获取某篇文章的附件,在 WordPress 3.6 以前的版本中,我们可以使用 get_children() 函数来获取,比如:
$args = array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
);
$attachments = get_children( $args ); |
$args = array(
'post_parent' => $post->ID,
'post_type' => 'attachment',
'post_mime_type' => 'image',
'posts_per_page' => -1,
'orderby' => 'menu_order',
'order' => 'ASC',
);
$attachments = get_children( $args );
更多详情请阅读 get_children() 官方文档。
WordPress 3.6 新增了一个新函数 get_attached_media() ,让我们获取附件变得更加简单,比如:
获取所有类型的附件:
$attachments = get_attached_media( '', $post->ID ); |
$attachments = get_attached_media( '', $post->ID );
获取图片附件:
$attachments = get_attached_media( 'image', $post->ID ); |
$attachments = get_attached_media( 'image', $post->ID );
获取音频附件:
$attachments = get_attached_media( 'audio', $post->ID ); |
$attachments = get_attached_media( 'audio', $post->ID );
获取视频附件:
$attachments = get_attached_media( 'video', $post->ID ); |
$attachments = get_attached_media( 'video', $post->ID );
更多详情,请阅读 get_attached_media() 官方文档
来源:
https://www.wpdaxue.com/get_attached_media.html
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_32256.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57