Vote count:
0
I want to display total of item in wordpress gallery each post. I code this, But it not work. The post display wrong number of item in gallery.
$args = array(
'order' => 'ASC',
'post_mime_type' => 'image/jpeg',
'post_parent' => $post->ID,
'post_status' => null,
'post_type' => 'attachment',
);
$pattern = get_shortcode_regex();
preg_match('/'.$pattern.'/s', $post->post_content, $matches);
if (is_array($matches) && $matches[2] == 'gallery') {
// do something
preg_match('/\[ gallery ids=\"(.*?)\"]/',$matches[0],$ids);
if (is_array($ids) && $ids[1] ) {
$photos = explode(',',$ids[1]);
} else {
$photos = get_children( $args );
}
$total_images = count($photos);
}
asked 14 secs ago
How to count image of gallery in wordpress gallery shortcode
Aucun commentaire:
Enregistrer un commentaire