Ticket #24688: 24688.diff
File 24688.diff, 2.4 KB (added by , 11 years ago) |
---|
-
media.php
1080 1080 * Retrieves the current attachment object from the $post global. 1081 1081 * 1082 1082 * @since 2.5.0 1083 * @uses _previous_image_posts_where_filter_once() 1084 * @uses _next_image_posts_where_filter_once() 1083 1085 * 1084 1086 * @param bool $prev Optional. Default is true to display previous link, false for next. 1085 1087 */ 1086 1088 function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) { 1089 $adjacent = $prev ? 'previous' : 'next'; 1090 $order = $prev ? 'DESC' : 'ASC'; 1087 1091 $post = get_post(); 1088 $attachments = array_values( get_children( array( 'post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID' ) ) ); 1092 add_filter( 'posts_where', "_{$adjacent}_image_posts_where_filter_once" ); 1093 $attachment = array_pop( get_children( array( 1094 'post_parent' => $post->post_parent, 1095 'post_status' => 'inherit', 1096 'post_type' => 'attachment', 1097 'post_mime_type' => 'image', 1098 'orderby' => "menu_order $order, ID $order", 1099 'posts_per_page' => 1, 1100 'suppress_filters' => false, 1101 ) ) ); 1089 1102 1090 foreach ( $attachments as $k => $attachment )1091 if ( $attachment->ID == $post->ID )1092 break;1093 1094 $k = $prev ? $k - 1 : $k + 1;1095 1096 1103 $output = $attachment_id = null; 1097 if ( isset( $attachment s[ $k ]) ) {1098 $attachment_id = $attachment s[ $k ]->ID;1104 if ( isset( $attachment ) ) { 1105 $attachment_id = $attachment->ID; 1099 1106 $output = wp_get_attachment_link( $attachment_id, $size, true, false, $text ); 1100 1107 } 1101 1108 1102 $adjacent = $prev ? 'previous' : 'next';1103 1109 echo apply_filters( "{$adjacent}_image_link", $output, $attachment_id, $size, $text ); 1104 1110 } 1105 1111 1106 1112 /** 1113 * Append to WHERE clause for selecting only the previous image. 1114 */ 1115 function _previous_image_posts_where_filter_once( $where ) { 1116 remove_filter( 'posts_where', __FUNCTION__ ); 1117 $post = get_post(); 1118 return "$where AND (menu_order < $post->menu_order OR (menu_order = $post->menu_order AND ID < $post->ID))"; 1119 } 1120 1121 /** 1122 * Append to WHERE clause for selecting only the next image. 1123 */ 1124 function _next_image_posts_where_filter_once( $where ) { 1125 remove_filter( 'posts_where', __FUNCTION__ ); 1126 $post = get_post(); 1127 return "$where AND (menu_order > $post->menu_order OR (menu_order = $post->menu_order AND ID > $post->ID))"; 1128 } 1129 1130 /** 1107 1131 * Retrieve taxonomies attached to the attachment. 1108 1132 * 1109 1133 * @since 2.5.0