Last active
August 29, 2015 14:17
-
-
Save thehung2224/c50e695b458d64104f62 to your computer and use it in GitHub Desktop.
Cách dùng Preg_match trong PHP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( !function_exists( 'extract_gallery_images_ids' ) ) { | |
function extract_gallery_images_ids() { | |
global $post; | |
$content = "[gallery ids="7,8,9,10"]"; | |
$pattern = "\[(\[?)(embed|wp_caption|caption|playlist|audio|video|dot_recommends|dot_recommended_posts|gallery)(?![\w-])([^\]\/]*(?:\/(?!\])[^\]\/]*)*?)(?:(\/)\]|\](?:([^\[]*+(?:\[(?!\/\2\])[^\[]*+)*+)\[\/\2\])?)(\]?)" | |
preg_match( "/$pattern/s", $content, $match ); | |
if( isset( $match[2] ) && ( "gallery" == $match[2] ) ) { | |
$atts = $match[3]; | |
$atts = shortcode_parse_atts( $match[3] ); | |
$gallery_images = 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' ); | |
return $gallery_images; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment