如何在WordPress 3.5的帖子中从图库中获取图像,因为图库不再与3.5中的帖子相关。 get_children() 不起作用,因为图库不是附件。任何帮助,不胜感激。
您可能必须解析短代码:
http://codex.wordpress.org/Gallery_Shortcode
使用正则表达式:
$post_content = get_the_content();
preg_match('/[gallery.*ids=.(.*).]/', $post_content, $ids);
$array_id = explode(",", $ids[1]);
`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之前习惯获得的内容。