Avoid a PHP notice in adjacent_image_link() if no images were found.
props nabil_kadimi. see #28361. Built from https://develop.svn.wordpress.org/trunk@28584 git-svn-id: http://core.svn.wordpress.org/trunk@28409 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
8653099a83
commit
2b6c8462b3
|
@ -1902,17 +1902,23 @@ function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) {
|
|||
$post = get_post();
|
||||
$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' ) ) );
|
||||
|
||||
foreach ( $attachments as $k => $attachment )
|
||||
if ( $attachment->ID == $post->ID )
|
||||
foreach ( $attachments as $k => $attachment ) {
|
||||
if ( $attachment->ID == $post->ID ) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$output = '';
|
||||
$attachment_id = 0;
|
||||
|
||||
if ( $attachments ) {
|
||||
$k = $prev ? $k - 1 : $k + 1;
|
||||
|
||||
$output = $attachment_id = null;
|
||||
if ( isset( $attachments[ $k ] ) ) {
|
||||
$attachment_id = $attachments[ $k ]->ID;
|
||||
$output = wp_get_attachment_link( $attachment_id, $size, true, false, $text );
|
||||
}
|
||||
}
|
||||
|
||||
$adjacent = $prev ? 'previous' : 'next';
|
||||
|
||||
|
|
Loading…
Reference in New Issue