Take the 2-minute tour ×

Im trying to get the next and previous attachment by the user its currently displaying, this is what I have and it works great except it gets all of the attachments instead of just the ones from a specific user.

<?php $attachment_size = apply_filters( 'twentyten_attachment_size', 900 ); 
echo wp_get_attachment_image($post->ID, array( $attachment_size, 9999) ); // filterable image width with, essentially, no limit for image height.?>

<div id="next-prev-links"><div class="previmg"><?php previous_image_link(); ?></div><p id="previmgtxt" class="imgtxt"><?php previous_image_link(false, 'Previous Photo'); ?></p>
<div class="nextimg"> <?php next_image_link(); ?></div><p id="nextimgtxt" class="imgtxt"><?php next_image_link(false, 'Next Photo'); ?></p></div>
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Hi @Jeremy Love:

Good question! And it's a good question because there do not appear to be any hooks to allow you to write code to filtering by author.

Sadly that means to copy their copy to make your own functions so you can make the required 1 line change (in this case, it's 'post_author' => $post->post_author,). Here are functions you should be able to use:

function yoursite_previous_image_link($size = 'thumbnail', $text = false) {
  yoursite_adjacent_image_link(true, $size, $text);
function yoursite_next_image_link($size = 'thumbnail', $text = false) {
  yoursite_adjacent_image_link(false, $size, $text);
function yoursite_adjacent_image_link($prev=true,$size='thumbnail',$text=false) {
  global $post;
  $post = get_post($post);
  $attachments = array_values(get_children( array(
   'post_author' => $post->post_author,
   '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 )
  $k = $prev ? $k - 1 : $k + 1;
  if ( isset($attachments[$k]) )
    echo wp_get_attachment_link($attachments[$k]->ID, $size, true, false, $text);
share|improve this answer
Thanks didnt, work for what I was trying to do but worked for something else I needed :) –  Jeremy Love Jan 30 '11 at 20:13
@Jeremy Love - How did it not work? –  MikeSchinkel Jan 31 '11 at 1:06
add comment

Your Answer


