'image'
);
$thumb_format = '';
$url = $img[0];
}
}
printf( $thumb_format, $thumb, $url, $init );
}
/**
* Show featured gallery for gallery post format
*/
function azeria_post_gallery() {
$post_id = get_the_ID();
// first - try to get images from galleries in post
$post_gallery = get_post_gallery( $post_id, false );
if ( ! empty( $post_gallery['ids'] ) ) {
$post_gallery = explode( ',', $post_gallery['ids'] );
} elseif ( ! empty( $post_gallery['src'] ) ) {
$post_gallery = $post_gallery['src'];
} else {
$post_gallery = false;
}
// if can't try to catch images inserted into post
if ( ! $post_gallery ) {
$post_gallery = azeria_post_images( $post_id, 15 );
}
// and if not find any images - try to get images attached to post
if ( ! $post_gallery || empty( $post_gallery ) ) {
$attachments = get_children( array(
'post_parent' => $post_id,
'posts_per_page' => 3,
'post_status' => 'inherit',
'post_type' => 'attachment',
'post_mime_type' => 'image',
) );
if ( $attachments && is_array( $attachments ) ) {
$post_gallery = array_keys( $attachments );
}
}
if ( ! $post_gallery || empty( $post_gallery ) ) {
return false;
}
$output = azeria_get_gallery_html( $post_gallery, array( 'id' => $post_id ) );
echo $output;
}
/**
* Build default gallery HTML from images array.
*/
function azeria_get_gallery_html( $images, $atts = array() ) {
$atts = wp_parse_args( $atts, array(
'link' => ''
) );
$id = isset( $atts['id'] ) ? $atts['id'] : rand( 0, 999 );
$default_slider_init = array(
'infinite' => true,
'speed' => 400,
'fade' => true,
'cssEase' => 'linear',
'adaptiveHeight' => true,
'dots' => false,
'prevArrow' => '.entry-gallery-prev-' . $id,
'nextArrow' => '.entry-gallery-next-' . $id,
);
/**
* Filter default gallery slider inits.
*/
$init = apply_filters( 'azeria_post_gallery_slider_init', $default_slider_init );
$init = wp_parse_args( $init, $default_slider_init );
$init = json_encode( $init );
$default_gall_init = array(
'delegate' => '.popup-gallery-item',
'type' => 'image',
'gallery' => array(
'enabled' => true
)
);
/**
* Filter default gallery popup inits.
*/
$gall_init = apply_filters( 'azeria_post_gallery_popup_init', $default_gall_init );
$gall_init = wp_parse_args( $gall_init, $default_gall_init );
$gall_init = json_encode( $gall_init );
$items = array();
$counter = 0;
foreach ( $images as $img ) {
$caption = '';
if ( 0 === $counter ) {
$nth_class = '';
$counter++;
} else {
$nth_class = ' nth-child';
}
if ( 0 < intval( $img ) ) {
$image = wp_get_attachment_image( $img, 'post-thumbnail', '' );
$url = wp_get_attachment_url( $img );
$attachment = get_post( $img );
if ( ! empty( $attachment->post_excerpt ) ) {
$caption_class = 'entry-gallery-caption';
$caption_text = wptexturize( $attachment->post_excerpt );
$caption = '
';
$url = $img;
}
if ( ! empty( $atts['link'] ) && 'none' === $atts['link'] ) {
$format = '