Created
March 18, 2014 23:00
-
-
Save jocastaneda/9631636 to your computer and use it in GitHub Desktop.
Count how many galleries the post has and count all the images. Does require WP 3.6+
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
<?php | |
// Get all the galleries in the current post | |
$galleries = get_post_galleries( get_the_ID(), false ); | |
// Count all the galleries | |
$total_gal = count( $galleries ); | |
/** | |
* count all the images | |
* @param array $array The array needed | |
* @return int returns the number of images in the post | |
*/ | |
function _get_total_images( $array ){ | |
$key = 0; | |
$src = 0; | |
while ( $key < count( $array ) ){ | |
$src += count( $array[$key]['src'] ); | |
$key++; | |
} | |
return intval( $src ); | |
} | |
echo _get_total_images( $galleries ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment