pstagg
Forum Replies Created
Viewing 1 replies (of 1 total)
-
Forum: Themes and Templates
In reply to: previous_image_link()Some may be interested in this variant:
For image links I wanted something functional equivalent to:
previous_post_link('<li>%link</li>');So thanks to this thread I came up with this:
In functions.php:
function ps_previous_image_link( $f ) { $i = ps_adjacent_image_link( true ); if ( $i ) { echo str_replace("%link", $i, $f); } } function ps_next_image_link( $f ) { $i = ps_adjacent_image_link( false ); if ( $i ) { echo str_replace("%link", $i, $f); } } function ps_adjacent_image_link($prev = true) { global $post; $post = get_post($post); $attachments = array_values(get_children(Array('post_parent' => $post->post_parent, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'orderby' => 'menu_order ASC, ID ASC'))); foreach ( $attachments as $k => $attachment ) { if ( $attachment->ID == $post->ID ) { break; } } $k = $prev ? $k - 1 : $k + 1; if ( isset($attachments[$k]) ) { return wp_get_attachment_link($attachments[$k]->ID, 'thumbnail', true); } else { return false; } }In image.php:
<ol> <?php ps_previous_image_link( '<li>%link</li>' ) ?> <?php ps_next_image_link( '<li>%link</li>' ) ?> </ol>Thanks guys.
Viewing 1 replies (of 1 total)