Obter todas as imagens na Galeria de Mídia?
-
-
Você quer dizertodas asimagensem toda abiblioteca demídia (isto é,todo o site)?Do you mean all images in the entire Media library (i.e., site-wide)?
- 0
- 2011-03-12
- ZaMoose
-
6 respostas
- 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 asimagens URLestão agoraem
$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
;-
Hum. Parece que @somaticme bateunisso.Ao contrário de sua solução acima,aminha só receberáimagens.um.. looks like @somatic has beat me to it. Unlike his solution above, mine will only get images.
- 0
- 2011-03-12
- Azizur Rahman
-
Obviamente,nossosmétodos são semelhantes ...e Azizurestá certo,adicionando o 'post_mime_type' a qualquer consultairá restringir ostipos retornados. Uma coisa a considerar: o GUIDgeralmente contém o URL completopara aimagem,masnão é umafonte confiável.Éestático,gerado apenas uma vez quando opost é criadoe é construídono URL do site atuale naestrutura dapasta demídia.Masessaestrutura depastas *e * O domíniopodemudarem algummomentoe,em seguida,o GUIDnão émais o URL daimagem real,apenas um registro do quefoi quandofoi criado ...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 resposta é **errada **.Não recebeimagens dabiblioteca demídia.Obtémimagens usadas dentro deposts.Imagensnão utilizadasnão sãoencontradas!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áerrado?Ou devoperguntar 'ainda'errado?Eupercebo queestou comentando quase 2 anos depois,mastentei issono WP 3.6e estou recebendoimagens que acabei de adicionar àbiblioteca demídia sem adicioná-las a quaisquerposts:/@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
-
Pode ser umaperguntaestúpida,mas comoeuteria agora os diferentestamanhos deimagem?Might be a stupid question, but how would I now get the different image sizes?
- 0
- 2016-07-17
- Frederik Witte
-
@Frederikwitte vocêpode combinar [get_intermediate_image_sizes] (https://developer.wordpress.org/reference/functions/get_intermediate_image_sizes/)e [wp_get_attachment_image_src] (https://developer.wordpress.org/reference/functions/wp_get_attachment_image_src/)para obtertodos os URLs.@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
-
Yaaaaaaaaaaaaaaas.yaaaaaaaaaaaaaaaaas
- 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;
Consulte obanco de dadosparatodos ositens dabiblioteca demídia (não apenas os anexados aposts),pegue o URL,despejetodosem
$list
Array.$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' ); } ?>
Issopuxatodos os anexospara umapostagem. Anexarmaisimagenspara umpost,e será listado
<?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
ok y usoueste códigoparamostrartodas asimagensnabiblioteca demídia!
$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>"; } }
e se você souber ométodoparamostrarpaginação,porfavor 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 quenãofoi atualizado há algumtempo,mas o mídiaGaleria debiblioteca Pluginpode ser umbomexemplopara começar a olhar.
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
Esta é apenas uma versãomais curta deste Resposta
get_posts()
array_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 );
Existe umamaneira debuscar os URLs de todas imagensnagaleria demídia?
Eu acho queesta seria umamaneirafácil de um siteter umapágina defotos que apenaspuxatodas asimagens dagaleria demídia,concedida que só serianecessáriaem certos cenários.
Eunãopreciso deinstruções sobre como criar umapágina defotos,apenas comopuxartodos os URLs daimagem.Obrigado!