Make WordPress Core


Ignore:
Timestamp:
08/04/2009 07:32:18 AM (16 years ago)
Author:
azaozz
Message:

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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/media.php

    r11746 r11771  
    662662        'captiontag' => 'dd',
    663663        'columns'    => 3,
    664         'size'       => 'thumbnail'
     664        'size'       => 'thumbnail',
     665        'include'    => '',
     666        'exclude'    => ''
    665667    ), $attr));
    666668
    667669    $id = intval($id);
    668     $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
     670    if ( 'RAND' == $order )
     671        $orderby = 'none';
     672
     673    if ( !empty($include) ) {
     674        $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
     675
     676        $attachments = array();
     677        foreach ( $_attachments as $key => $val ) {
     678            $attachments[$val->ID] = $_attachments[$key];
     679        }
     680    } elseif ( !empty($exclude) ) {
     681        $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
     682    } else {
     683        $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) );
     684    }
    669685
    670686    if ( empty($attachments) )
Note: See TracChangeset for help on using the changeset viewer.