从Post画廊WordPress 3.5获取图像 [英] Get images from post's gallery WordPress 3.5

查看:79
本文介绍了从Post画廊WordPress 3.5获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从WordPress 3.5中的帖子中的图库中获取图像,因为图库不再与3.5中的帖子相关. get_children()不起作用,因为画廊不是附件.感谢您的帮助.

How to get images from a gallery in a post in WordPress 3.5 as gallery is no longer related to posts in 3.5. get_children() doesnot work as gallery is not attachment. Any help is appreciated.

推荐答案

`global $post;
    $post_subtitrare = get_post( $post->ID );
    $content = $post_subtitrare->post_content;
    $pattern = get_shortcode_regex();
    preg_match( "/$pattern/s", $content, $match );
    if( isset( $match[2] ) && ( "gallery" == $match[2] ) ) {
        $atts = shortcode_parse_atts( $match[3] );
        $attachments = isset( $atts['ids'] ) ? explode( ',', $atts['ids'] ) : get_children( 'post_type=attachment&post_mime_type=image&post_parent=' . $post->ID .'&order=ASC&orderby=menu_order ID' );
    }`

$attachments将为您提供WordPress 3.5之前的习惯.

The $attachments will get you what you are used to getting prior to WordPress 3.5.

这篇关于从Post画廊WordPress 3.5获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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