Advertisement
dragunoff

[WP] Auto open fancybox for first PDF attachment

May 7th, 2011
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.71 KB | None | 0 0
  1.  
  2. <?php // Show attachments for the current post
  3. $args = array(
  4.     'post_type' => 'attachment',
  5.     'numberposts' => -1,
  6.     'post_status' => null,
  7.     'post_mime_type' => 'application/pdf',
  8.     'post_parent' => $post->ID
  9.     );
  10.    
  11. $attachments = get_posts($args);
  12.  
  13. if ($attachments) {
  14.  
  15.     foreach ( $attachments as $attachment ) {
  16.        
  17.         // build embed link
  18.         $embed_link = 'http://docs.google.com/viewer?url=' . wp_get_attachment_url( $attachment->ID ) . '&amp;embedded=true';
  19.        
  20.         // thumbnail
  21.         $output = '<a href="' . $embed_link . '" class="fancybox-iframe fancybox" id="fancybox-auto">';
  22.             $output .= get_the_post_thumbnail( $post->ID, 'large' );
  23.         $output .= '</a>';
  24.        
  25.         // print
  26.         echo $output;
  27.     }
  28.    
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement