Ver Mensaje Individual
  #11 (permalink)  
Antiguo 06/06/2011, 08:01
Avatar de AlZuwaga
AlZuwaga
Colaborador
 
Fecha de Ingreso: febrero-2001
Ubicación: 34.517 S, 58.500 O
Mensajes: 14.550
Antigüedad: 23 años, 2 meses
Puntos: 535
Respuesta: subida de fotos

Disculpen la demora. Me había olvidado de pasar a agradecer. Todo resultó de maravillas. Básicamente utilicé esta función:

Código PHP:
Ver original
  1. function insert_attachment($file_handler,$post_id,$setthumb='false') {
  2.         // check to make sure its a successful upload
  3.         if ($_FILES[$file_handler]['error'] !== UPLOAD_ERR_OK) __return_false();
  4.        
  5.         require_once(ABSPATH . "wp-admin" . '/includes/image.php');
  6.         require_once(ABSPATH . "wp-admin" . '/includes/file.php');
  7.         require_once(ABSPATH . "wp-admin" . '/includes/media.php');
  8.        
  9.         $attach_id = media_handle_upload( $file_handler, $post_id );
  10.        
  11.         if ($setthumb) update_post_meta($post_id,'_thumbnail_id',$attach_id);
  12.        
  13.         // Update the post into the database
  14.         $my_post = array();
  15.         $my_post['ID'] = $attach_id;
  16.         $my_post['post_title'] = $_POST['titulo'];
  17.         $my_post['post_content'] = $_POST['comentario'];
  18.         wp_update_post( $my_post );
  19.        
  20.         return $attach_id;
  21.     }//function insert_attachment
  22.  
  23. // código innecesario de mostrar
  24.  
  25.     if ($_FILES['file']['error'] == 0 && $_POST['titulo'] != '') {
  26.         $filetype = wp_check_filetype(basename($_FILES['file']['name']), null );
  27.        
  28.         //echo $filetype['type']; exit;
  29.         if($filetype['type'] != 'image/jpeg'){
  30.             $fan_errores = true;
  31.             $fan_mensaje = '<p>Sólo imágenes JPG por favor.</p>';
  32.         }
  33.         else{
  34.             $post_id = 474;
  35.             foreach ($_FILES as $file => $array) {
  36.                 $newupload = insert_attachment($file,$post_id);
  37.                 // $newupload returns the attachment id of the file that
  38.                 // was just uploaded. Do whatever you want with that now.
  39.        
  40.                 $from = get_option('admin_email');
  41.                 $headers = 'From: '.$from . "\r\n";
  42.                 $headers .= 'Bcc: [email protected]' . "\r\n";
  43.                 $subject = "Nueva fan foto subida";
  44.                 $msg = "Han subido una fan foto.\nLuego modifico este email para dar más datos.";
  45.                 wp_mail( '[email protected]', $subject, $msg, $headers );
  46.             }//foreach
  47.            
  48.             header("Location: /fan-fotos/?gracias");
  49.         }//
  50.     }
  51.     else{
  52.         $fan_errores = true;
  53.         $fan_mensaje = '<p>Seguramente te olvidaste de elegir tu foto o tal vez de escribir un título. Dale de nuevo.</p>';
  54.     }//if ($_FILES['file']['error'] == 0 && $_POST['titulo'] != '')
  55.  
  56. // código innecesario de mostrar


Luego muestro 6 fotos aleatorias:

Código PHP:
Ver original
  1. function get_random_gallery_images(){
  2.     global $wpdb,$post;
  3.         $ids = "";
  4.         $counter = 0;
  5.         $number_of_posts = 6;
  6.  
  7.         $args = array(
  8.         'post_type'     => 'attachment',
  9.         'numberposts'   => $number_of_posts,
  10.         'post_status'   => null,
  11.         'orderby'       => 'rand',
  12.         'meta_key'      => '_mySelectBox',
  13.         'meta_value'    => 'fanfoto_aprobada',
  14.         'post_parent'   => 474
  15.         );
  16.         $attachments = get_posts($args);
  17.         if ($attachments) {
  18.             foreach ($attachments as $attachment) {
  19.  
  20.                 if ($counter != 0) {
  21.                     $ids .= ','.$attachment->ID;
  22.                 }
  23.                 else {
  24.                     $ids .= $attachment->ID;
  25.                 }
  26.                 $counter++;
  27.             }
  28.         }
  29.         return $ids;
  30. }
  31.  
  32. $attachment_ids = get_random_gallery_images();
  33. //echo $attachment_ids;
  34.  
  35. $fanfotos = new WP_Query('pagename=fan-fotos&showposts=1');
  36. while ($fanfotos->have_posts()) : $fanfotos->the_post();
  37. //  echo get_the_content();
  38.     echo do_shortcode('[gallery link="file" size="fan_fotos_thumb" include="'.$attachment_ids.'" orderby="rand" columns="0"]');
  39. endwhile; //$fanfotos


Las fotos aprobadas tienen un custom field con el valor fanfoto_aprobada que lo establece el responsable de dicha tarea a cada imagen.
__________________
...___...