From bbefcaca3b716990f514bdb03b94508d7f70a67b Mon Sep 17 00:00:00 2001 From: azaozz Date: Tue, 4 Aug 2009 07:32:18 +0000 Subject: [PATCH] Add support for 'include' and 'exclude' to [gallery] (include="123,456" would show only these attachments regardless of the parent post, exclude="789,123" would exclude these attachments and show the rest). git-svn-id: http://svn.automattic.com/wordpress/trunk@11771 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/media.php | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/wp-includes/media.php b/wp-includes/media.php index e720879c1..911f4e913 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -661,11 +661,27 @@ function gallery_shortcode($attr) { 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, - 'size' => 'thumbnail' + 'size' => 'thumbnail', + 'include' => '', + 'exclude' => '' ), $attr)); $id = intval($id); - $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); + if ( 'RAND' == $order ) + $orderby = 'none'; + + if ( !empty($include) ) { + $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); + + $attachments = array(); + foreach ( $_attachments as $key => $val ) { + $attachments[$val->ID] = $_attachments[$key]; + } + } elseif ( !empty($exclude) ) { + $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); + } else { + $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); + } if ( empty($attachments) ) return '';