IT-Swarm.Net

仅限作者获取下一个和上一个附件

我正在尝试通过它当前正在显示的用户获取下一个和之前的附件,这是我拥有的并且它工作得很好,除了它获取所有附件而不仅仅是来自特定用户的附件。.

<p>
<?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.?>
</p>

<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>
2
Jeremy Love

@ Jeremy Love :

好问题!这是一个很好的问题,因为似乎没有任何钩子可以让你编写代码来过滤作者。.

可悲的是,这意味着复制他们的副本以创建自己的函数,这样你就可以进行所需的1行更改(在这种情况下,它是'post_author' => $post->post_author,)。这里有你应该能够的函数使用:

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 )
      break;
  $k = $prev ? $k - 1 : $k + 1;
  if ( isset($attachments[$k]) )
    echo wp_get_attachment_link($attachments[$k]->ID, $size, true, false, $text);
}
1
MikeSchinkel

快速,可靠且价格合理的云托管

注册并在30天内获得$50奖金!