Advertisement
Guest User

widget_listattach

a guest
Aug 24th, 2011
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.50 KB | None | 0 0
  1. function widget_listattach($args) {
  2.         global $wpdb, $post;
  3.  
  4.         extract($args);
  5.         $options = array_merge(widget_listattach_options(), get_option('widget_listattach'));
  6.         unset($options[0]); //returned by get_option(), but we don't need it
  7.         $args = array(
  8.             'post_type' => 'attachment',
  9.             'post_mime_type' => $options['type'],
  10.             'numberposts' => $options['count'],
  11.                 'orderby' => $options['orderby'],
  12.                 'order' => $options['order'],
  13.             'post_parent' => $post->ID
  14.         );
  15.         $attachments = get_children($args);
  16.         if ($attachments) {
  17.             echo $before_widget . $before_title .$options['title'] . $after_title;
  18.             echo '<ul>';
  19.             foreach ($attachments as $attachment) {
  20.                 //echo '<li>'.$attachment->post_title.'</li>';
  21.                 //the_attachment_link($attachment->ID, false);
  22.                 $mime_parts = explode("/", $attachment-> post_mime_type);
  23.                 $mime_class = 'class="mime-'.$mime_parts[count($mime_parts)-1].'"';
  24.                     $descr = 'post_title';
  25.                      if ($options['display'] == 'caption') {
  26.                         $descr = 'post_excerpt';
  27.                     } else if ($options['display'] == 'description') {
  28.                         $descr = 'post_content';  
  29.                     }
  30.                     if ($attachment->$descr) {
  31.                         echo '<li '.$mime_class.'><a href="'.wp_get_attachment_url($attachment->ID).'">'.$attachment->$descr.'</a></li>';    
  32.                     } else {
  33.                         echo '<li '.$mime_class.'>'.wp_get_attachment_link($attachment->ID).'</li>';
  34.                     }
  35.             }
  36.             echo '</ul>'.$after_widget;
  37.         }
  38.        
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement