¿Obtener todas las imágenes de la galería multimedia?
-
-
¿Te refieres atodas lasimágenes detoda labiblioteca demedios (es decir,en todoel sitio)?Do you mean all images in the entire Media library (i.e., site-wide)?
- 0
- 2011-03-12
- ZaMoose
-
6 respuestas
- votos
-
- 2011-03-12
$query_images_args = array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'posts_per_page' => - 1, ); $query_images = new WP_Query( $query_images_args ); $images = array(); foreach ( $query_images->posts as $image ) { $images[] = wp_get_attachment_url( $image->ID ); }
Todas las URL de lasimágenesestán ahoraen
$images
;$query_images_args = array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'posts_per_page' => - 1, ); $query_images = new WP_Query( $query_images_args ); $images = array(); foreach ( $query_images->posts as $image ) { $images[] = wp_get_attachment_url( $image->ID ); }
All the images url are now in
$images
;-
um ..parece que @somatic seme ha adelantado.A diferencia de su solución anterior,lamía solo obtendráimágenes.um.. looks like @somatic has beat me to it. Unlike his solution above, mine will only get images.
- 0
- 2011-03-12
- Azizur Rahman
-
obviamentenuestrosmétodos son similares ... y azizurtiene razón,agregarel 'post_mime_type' a cualquiera de las consultas reducirá lostipos devueltos. Una cosa a considerar:elguid amenudo contiene la URL completa de laimagen,peronoes unafuente confiable.Esestático,segenera solo una vez cuando se crea lapublicación y sebasaen la URL del sitio actual y laestructura de la carpetamultimedia.Peroesaestructura de carpetas * y *el dominiopodrían cambiaren algúnmomento,y luegoelguid yanoes la URL de laimagen real,solo un registro de lo queera cuando se creó ...obviously our methods are similar... and azizur is right, adding the 'post_mime_type' to either query will narrow the types returned. one thing to consider: the guid often does contain the full url to the image, but it is not a reliable source. It is static, generated only once when the post is created, and is built on the current site url and the media folder structure. But that folder structure *and* the domain could change at some point, and then the guid is not the actual image URL anymore, just a record of what it was when it was created...
- 2
- 2011-03-13
- somatic
-
Esta respuestaes ** INCORRECTA **.No obtieneimágenes de labibliotecamultimedia.Obtieneimágenes utilizadas dentro de laspublicaciones.¡No seencuentran lasimágenesno utilizadas!This answer is **WRONG**. It does not get images from Media Library. It gets images used inside posts. Unused images are not found!
- 1
- 2011-10-10
- Christian
-
@Christian - ¿estámal?¿O deberíapreguntar "todavía"mal?Me doy cuenta de queestoy comentando casi 2 años después,peroprobéestoen WP 3.6 yestoy recibiendoimágenes que acabo de agregar a labiblioteca demedios sin agregarlas aningunapublicación:/@Christian - is it wrong? Or should I ask 'still' wrong? I realise I'm commenting almost 2 years later, but I tried this out on WP 3.6 and I'm receiving images that I've just added to the media library without adding them to any posts :/
- 0
- 2013-08-16
- Chris Kempen
-
Podría ser unapreguntaestúpida,pero ¿cómo obtendría ahora los diferentestamaños deimagen?Might be a stupid question, but how would I now get the different image sizes?
- 0
- 2016-07-17
- Frederik Witte
-
@FrederikWittepuede combinar [get_intermediate_image_sizes] (https://developer.wordpress.org/reference/functions/get_intermediate_image_sizes/) y [wp_get_attachment_image_src] (https://developer.wordpress.org/reference/functions/wp_get_atta_sizes/)todas las URL.@FrederikWitte you can combine [get_intermediate_image_sizes](https://developer.wordpress.org/reference/functions/get_intermediate_image_sizes/) and [wp_get_attachment_image_src](https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/) to get all the urls.
- 0
- 2016-07-17
- Azizur Rahman
-
yaaaaaaaaaaaaaaaaasyaaaaaaaaaaaaaaaaas
- 0
- 2018-02-22
- Zach Smith
-
- 2011-03-12
$media_query = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'posts_per_page' => -1, ) ); $list = array(); foreach ($media_query->posts as $post) { $list[] = wp_get_attachment_url($post->ID); } // do something with $list here;
Consultaen labase de datostodos loselementos de labiblioteca demedios (no solo los adjuntos a laspublicaciones),toma su URL y volcatodosen lamatriz
$list
.$media_query = new WP_Query( array( 'post_type' => 'attachment', 'post_status' => 'inherit', 'posts_per_page' => -1, ) ); $list = array(); foreach ($media_query->posts as $post) { $list[] = wp_get_attachment_url($post->ID); } // do something with $list here;
Query the db for all media library items (not just ones attached to posts), grab their url, dump them all in
$list
array. -
- 2011-03-12
<?php $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' =>'image') ); foreach ( $attachments as $attachment_id => $attachment ) { echo wp_get_attachment_image( $attachment_id, 'medium' ); } ?>
Estoextraetodos los archivos adjuntos de unapublicación/página. Adjuntemásimágenes a unapublicación y apareceráen la lista
<?php $attachments = get_children( array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'post_mime_type' =>'image') ); foreach ( $attachments as $attachment_id => $attachment ) { echo wp_get_attachment_image( $attachment_id, 'medium' ); } ?>
This pulls all attachments for a post/page. Attach more images to a post, and it will be listed
-
- 2012-02-27
¡De acuerdo,uséeste códigoparamostrar TODAS lasimágenesen labibliotecamultimedia!
$args = array( 'post_type' => 'attachment', 'post_status' => 'published', 'posts_per_page' =>25, 'post_parent' => 210, // Post-> ID; 'numberposts' => null, ); $attachments = get_posts($args); $post_count = count ($attachments); if ($attachments) { foreach ($attachments as $attachment) { echo "<div class=\"post photo col3\">"; $url = get_attachment_link($attachment->ID);// extraigo la _posturl del attachmnet $img = wp_get_attachment_url($attachment->ID); $title = get_the_title($attachment->post_parent);//extraigo titulo echo '<a href="'.$url.'"><img title="'.$title.'" src="'.get_bloginfo('template_url').'/timthumb.php?src='.$img.'&w=350&h=500&zc=3"></a>'; echo "</div>"; } }
y si conoceelmétodoparamostrar lapaginación,responda.
ok y used this code for show ALL images in media Library!
$args = array( 'post_type' => 'attachment', 'post_status' => 'published', 'posts_per_page' =>25, 'post_parent' => 210, // Post-> ID; 'numberposts' => null, ); $attachments = get_posts($args); $post_count = count ($attachments); if ($attachments) { foreach ($attachments as $attachment) { echo "<div class=\"post photo col3\">"; $url = get_attachment_link($attachment->ID);// extraigo la _posturl del attachmnet $img = wp_get_attachment_url($attachment->ID); $title = get_the_title($attachment->post_parent);//extraigo titulo echo '<a href="'.$url.'"><img title="'.$title.'" src="'.get_bloginfo('template_url').'/timthumb.php?src='.$img.'&w=350&h=500&zc=3"></a>'; echo "</div>"; } }
and if you know method for show pagination, please answer.
-
- 2011-03-12
Parece queno se ha actualizadoen untiempo,pero MediaEl complemento Galería de labiblioteca podría ser unbuenejemplopara comenzar amirar.
It looks as though it hasn't been updated in a while, but the Media Library Gallery plugin might be a good example to start looking at.
-
- 2016-01-20
Estaes solo una versiónmás corta deesta respuesta con
get_posts()
yarray_map()
.$image_ids = get_posts( array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'posts_per_page' => - 1, 'fields' => 'ids', ) ); $images = array_map( "wp_get_attachment_url", $image_ids );
This is just a shorter version of this answer using
get_posts()
andarray_map()
.$image_ids = get_posts( array( 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_status' => 'inherit', 'posts_per_page' => - 1, 'fields' => 'ids', ) ); $images = array_map( "wp_get_attachment_url", $image_ids );
¿Hay algunaforma de obtener las URL de TODAS lasimágenesen lagaleríamultimedia?
Creo queesta sería unamanerafácilpara que un sitio webtenga unapágina deimágenes que simplementeextraigatodas lasimágenes de lagalería demedios,dado que solo seríanecesarioen ciertosescenarios.
Nonecesitoinstrucciones sobre cómo crear unapágina deimágenes,solo sobre cómoextraertodas las URL de lasimágenes.¡Gracias!