Skip to content

Instantly share code, notes, and snippets.

@umuthan
Created August 24, 2012 21:34
Show Gist options
  • Save umuthan/3455884 to your computer and use it in GitHub Desktop.
Save umuthan/3455884 to your computer and use it in GitHub Desktop.
Really simple gallery widget extension sub page support
52c52,53
< $query_images_args = array(
---
>
> $query_pages_args = array(
54,56c55,57
< 'post_status' => 'inherit',
< 'post_type' => 'attachment',
< 'post_mime_type' => 'image',
---
> 'post_status' => 'publish',
> 'post_type' => 'page',
> 'sort_order' => $order,
58d58
< 'order' => $order,
60c60
<
---
>
63c63
< $query_images_args['orderby'] = 'rand';
---
> $query_pages_args['orderby'] = 'rand';
64a65,86
>
> $pages = get_children( $query_pages_args );
>
> $pages[] = get_page($post_id);
>
> $totalPages = count($pages);
>
> if( $totalPages != 0 ) {
>
> foreach( $pages as $value ){
>
> $query_images_args = array(
> 'post_parent' => $value->ID,
> 'post_status' => 'inherit',
> 'post_type' => 'attachment',
> 'post_mime_type' => 'image',
> 'numberposts' => -1,
> );
>
> $attachmentsCount = count(get_children( $query_images_args ));
> if($attachmentsCount==0) $totalPages--;
> }
66,68d87
< // limited number of images
< if ($num_images != 0) {
< $query_images_args['numberposts'] = $num_images;
69a89,104
>
> foreach( $pages as $value ){
>
> $query_images_args = array(
> 'post_parent' => $value->ID,
> 'post_status' => 'inherit',
> 'post_type' => 'attachment',
> 'post_mime_type' => 'image',
> 'numberposts' => -1,
> 'order' => $order,
> );
>
> // randomly ordered
> if ($order == 'rand') {
> $query_images_args['orderby'] = 'rand';
> }
71,78c106,108
< $attachments = get_children( $query_images_args );
<
< if ( !empty($attachments) ) {
< foreach( $attachments as $id => $attachment ) {
< $image = wp_get_attachment_image_src($id, $image_size);
< $image['ID'] = $id;
< $image['title'] = $attachment->post_title;
< $images[] = $image;
---
> // limited number of images
> if ($num_images != 0) {
> $query_images_args['numberposts'] = round($num_images/$totalPages);
79a110,121
>
> $attachments = get_children( $query_images_args );
>
> if ( !empty($attachments) ) {
> foreach( $attachments as $id => $attachment ) {
> $image = wp_get_attachment_image_src($id, $image_size);
> $image['ID'] = $id;
> $image['title'] = $attachment->post_title;
> $images[] = $image;
> }
> }
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment