Advertisements

adjacent_image_link

Definition:
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) {}

Display next or previous image link that has the same post parent.
Retrieves the current attachment object from the $post global.

Parameters

  • bool $prev: Optional. Default is true to display previous link, false for next.
  • $size
  • $text

Source code

function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false) {

	global $post;

	$post = get_post($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 )

			break;



	$k = $prev ? $k - 1 : $k + 1;



	if ( isset($attachments[$k]) )

		echo wp_get_attachment_link($attachments[$k]->ID, $size, true, false, $text);

}

387

Advertisements

No comments yet... Be the first to leave a reply!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: