Obtenir toutes les images dans la galerie multimédia?
-
-
Voulez-vous diretoutes lesimages de labibliothèquemultimédiaentière (c'est-à-dire à l'échelle du site)?Do you mean all images in the entire Media library (i.e., site-wide)?
- 0
- 2011-03-12
- ZaMoose
-
6 réponses
- votes
-
- 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 ); }
Toutes les URL desimages sontmaintenant dans
$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
;-
euh ... on dirait que @somaticm'abattu.Contrairement à sa solution ci-dessus,lamienne n'obtiendra que desimages.um.. looks like @somatic has beat me to it. Unlike his solution above, mine will only get images.
- 0
- 2011-03-12
- Azizur Rahman
-
évidemmentnosméthodes sont similaires ...et azizur a raison,ajouter le 'post_mime_type' à l'une ou l'autre des requêtes réduira lestypes renvoyés. une chose à considérer: le GUID contient souvent l'URL complète de l'image,mais cen'estpas une sourcefiable.Ilest statique,généré une seulefois lors de la création de l'article,et est construit sur l'URL du site actuelet la structure du dossiermultimédia.Mais cette structure de dossier *et * le domainepourraient changer à unmoment donné,et alors le GUIDn'estplus l'URL de l'image réelle,juste unenregistrement de ce qu'il était quandil a été créé ...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
-
Cette réponseest ** FAUX **.Iln'obtientpas d'images de lamédiathèque.Il obtient desimages utilisées à l'intérieur desmessages.Lesimagesinutilisées sontintrouvables!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-cemal?Ou devrais-je demander «toujours»mal?Jeme rends compte queje commentepresque 2 ansplustard,maisj'aiessayé cela sur WP 3.6et je reçois desimages queje viens d'ajouter à lamédiathèque sans les ajouter à aucun article:/@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
-
Peut-être une question stupide,mais commentpourrais-jemaintenant obtenir les différentestailles d'image?Might be a stupid question, but how would I now get the different image sizes?
- 0
- 2016-07-17
- Frederik Witte
-
@FrederikWitte,vouspouvez combiner [get_intermediate_image_sizes] (https://developer.wordpress.org/reference/functions/get_intermediate_image_sizes/)et [wp_get_attachment_image_src] (https://developer.wordpress.org/reference/functions/wp_get_sachment)totoutes les 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;
Recherchez dans labase de donnéestous les éléments de lamédiathèque (pas seulement ceux attachés aux articles),saisissez leur URL,videz-lestous dans letableau
$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' ); } ?>
Celaextraittoutes lespiècesjointes d'un article/d'unepage. Joindreplus d'images à unmessage,et il sera répertorié
<?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 a utilisé ce codepour afficher TOUTES lesimages de labibliothèquemultimé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>"; } }
et si vous connaissez laméthodepour afficher lapagination,veuillez répondre.
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
Il semble qu'iln'aitpas étémis àjour depuis un certaintemps,mais le MediaLeplugin Library Gallery pourrait être unbonexemplepour commencer à regarder.
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
Ceciestjuste une version abrégée de cette réponse en utilisant
get_posts()
etarray_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-t-il unmoyen de récupérer les URL de TOUTES lesimages dans lagaleriemultimédia?
Jepense que ce serait unmoyenfacilepour un site Web d'avoir unepage d'images quiextraittoutes lesimages de lagaleriemultimédia,bien que celane soitnécessaire que dans certains scénarios.
Jen'aipasbesoin d'instructionspour créer unepage d'images,mais simplementpourextrairetoutes les URL d'image.Merci!