如何在WordPress 3.5中的帖子中从图库中获取图像,因为画廊不再与3.5中的帖子相关。get_children()不起作用,因为图库不是附件。任何帮助都是非常感谢的。
发布于 2012-12-28 15:01:29
`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' );
}`在WordPress 3.5之前,$attachments将为您提供您所习惯的功能。
https://stackoverflow.com/questions/13873532
复制相似问题