Advertisement
Guest User

Wordpress Caption and Description

a guest
Jul 26th, 2011
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.75 KB | None | 0 0
  1. function retrieve_full_image_info($input){
  2.     $options = $input;
  3.     $numberofslides= $options['numberofslides'];
  4.     //Set an array to store all the image URLs from my options and the current index in the array.
  5.     $arrayofurls= array();
  6.     for ($i=0; $i<$numberofslides;$i++){
  7.         $arrayofurls[$i]=$options['wdlmg_image_option'.$i];
  8.         $arrayofurls[$i]['index']=$i;
  9.     }
  10.     //This below is what gets the attachment files.
  11.     $args = array( 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_parent' => null );
  12.     $attachments = get_posts( $args );
  13.     //Now we check if the urls we obtained from the media uploader with the attachment url
  14.     if (!empty($attachments)) {
  15.         foreach ( $attachments as $post ) {
  16.        
  17.         $id=$post->ID;
  18.         $current = wp_get_attachment_url($id);
  19.            
  20.             foreach ($arrayofurls as $url){
  21.             $wanted= $url['url'];
  22.                 if($current == $wanted){
  23.                     $index= $url['index'];
  24.                     setup_postdata($post);         
  25.                     $options['wdlmg_image_option'.$index]['id']=$id;
  26.                     $options['wdlmg_image_option'.$index]['title']=$post->post_title;
  27.                     $three= wp_get_attachment_image_src($id);
  28.                     $options['wdlmg_image_option'.$index]['width']=$three[1];
  29.                     $options['wdlmg_image_option'.$index]['height']=$three[2];
  30.                     $content= $post->post_content;
  31.                     $options['wdlmg_image_option'.$index]['description']=$content;
  32.                     //by default if caption is empty, its the description
  33.                     $caption=$post->post_excerpt;
  34.                     if($caption!=$content){
  35.                         $options['wdlmg_image_option'.$index]['caption']=$caption;
  36.                     }//end if
  37.                                         //remove this url from list since we got its details.
  38.                     unset($arrayofurls[$index]);   
  39.                 }//end if
  40.             }//end foreach
  41.         }//end foreach
  42.     }//endif
  43.     return $options;
  44. }//end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement