Ticket #12799: 12799.diff

File 12799.diff, 2.4 KB (added by jamescollins, 9 months ago)
  • media.php

     
    802802                'columns'    => 3, 
    803803                'size'       => 'thumbnail', 
    804804                'include'    => '', 
    805                 'exclude'    => '' 
     805                'exclude'    => '', 
     806                'numberimages'    => 0 
    806807        ), $attr)); 
    807808 
    808809        $id = intval($id); 
     810 
     811        $numberimages = intval($numberimages); 
     812        if ( $numberimages <= 0 ) 
     813                $numberimages = -1; 
     814 
    809815        if ( 'RAND' == $order ) 
    810816                $orderby = 'none'; 
    811817 
    812818        if ( !empty($include) ) { 
    813819                $include = preg_replace( '/[^0-9,]+/', '', $include ); 
    814                 $_attachments = get_posts( array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 
     820                $_attachments = get_posts( array('include' => $include, 'numberposts' => $numberimages, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 
    815821 
    816822                $attachments = array(); 
    817823                foreach ( $_attachments as $key => $val ) { 
     
    819825                } 
    820826        } elseif ( !empty($exclude) ) { 
    821827                $exclude = preg_replace( '/[^0-9,]+/', '', $exclude ); 
    822                 $attachments = get_children( array('post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 
     828                $attachments = get_children( array('numberposts' => $numberimages, 'post_parent' => $id, 'exclude' => $exclude, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 
    823829        } else { 
    824                 $attachments = get_children( array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 
     830                $attachments = get_children( array('numberposts' => $numberimages, 'post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby) ); 
    825831        } 
    826832 
    827833        if ( empty($attachments) ) 
    828834                return ''; 
    829835 
     836        // Necessary because in get_posts(), when specifying include="", the numberposts parameter is ignored (it's set to match the number if items in include="") 
     837        if ( $numberimages > 0 ) 
     838                $attachments = array_slice( $attachments, 0, $numberimages, true ); 
     839 
    830840        if ( is_feed() ) { 
    831841                $output = "\n"; 
    832842                foreach ( $attachments as $att_id => $attachment )