You appear to be a bot. Output may be restricted
Description
Get the attached imageReturn an array of images attached to a specific post ID Return Value: An array containing:
- $image[0] => url
- $image[1] => width
- $image[2] => height
- $image[3] => attachment id
Usage
$array = bw_get_attached_image( $post_id, $number, $orderby, $image_size );
Parameters
- $post_id
- ( integer ) optional – the parent post ID, or null
- $number
- ( integer ) optional default: 1 – the number of posts to retrieve
- $orderby
- ( string ) optional default: rand – how to select the image
- $image_size
- ( string ) optional default: thumbnail –
Returns
array the selected imageSource
File name: oik/includes/bw_images.incLines:
1 to 26 of 26
function bw_get_attached_image( $post_id = null, $number = 1, $orderby = 'rand', $image_size = 'thumbnail') { $args = array( 'post_type' => 'attachment' , 'numberposts' => $number , 'post_mime_type' => 'image' , 'orderby' => $orderby ); if ( $post_id == null) { $post_id = get_the_id(); $args['post_parent'] = $post_id; } else { //$args['ID'] = $post_id; $args['post_parent'] = $post_id; } //bw_trace2( $args, "args" ); //bw_backtrace(); $number = intval( $number ); $arr_attachment = get_posts( $args ); if ( count( $arr_attachment ) ) { foreach ( $arr_attachment as $index => $attachment ) { $arr_attachment[$index] = array_merge ( (array) wp_get_attachment_image_src($attachment->ID, $image_size), array($attachment->ID) ); } } //bw_trace( $arr_attachment, __FUNCTION__, __LINE__, __FILE__, "arr_attachment" ); return $arr_attachment; }View on GitHub View on Trac