我想在每个帖子中显示wordpress画廊中的项目总数。 我编码这个,但它不起作用。帖子在图库中显示错误的项目数。
$args = array(
'order' => 'ASC',
'post_mime_type' => 'image',
'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);
}