Fonction pour obtenir l'URL de l'image originale téléchargée - taille réelle
3 réponses
- votes
-
- 2014-11-03
Ilexiste quatretailles validesintégrées au cœur de WordPress.
the_post_thumbnail('thumbnail'); // Thumbnail (default 150px x 150px max) the_post_thumbnail('medium'); // Medium resolution (default 300px x 300px max) the_post_thumbnail('medium_large'); // Medium Large resolution (default 768px x 0(means automatic height by ratio) max) since WP version 4.4 the_post_thumbnail('large'); // Large resolution (default 640px x 640px max) the_post_thumbnail('full'); // Original image resolution (unmodified)
Le dernierest celui que vous recherchez.
Ce qui suit renvoie l'URL.
<?php $src = wp_get_attachment_image_src( $attachment_id, $size, $icon ); echo $src[0];
L'ensemble du codepeut ressembler à ça:
<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full', false ); echo $src[0]; // the url of featured image
Pourplus d'informations,ici .
There are four valid sizes built in to the WordPress core.
the_post_thumbnail('thumbnail'); // Thumbnail (default 150px x 150px max) the_post_thumbnail('medium'); // Medium resolution (default 300px x 300px max) the_post_thumbnail('medium_large'); // Medium Large resolution (default 768px x 0(means automatic height by ratio) max) since WP version 4.4 the_post_thumbnail('large'); // Large resolution (default 640px x 640px max) the_post_thumbnail('full'); // Original image resolution (unmodified)
The last is one you're looking for.
The following returns the URL.
<?php $src = wp_get_attachment_image_src( $attachment_id, $size, $icon ); echo $src[0];
The whole code can look like that:
<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full', false ); echo $src[0]; // the url of featured image
More information can be found here.
-
Mercipour votre réponse.Je rechercheen fait unefonctionpour renvoyer "l'URL" de l'imageet non l'imageelle-même.Je doute donc quethe_post_thumbnailfonctionnepour cela.Oupeut-être queje metrompe?Thanks for your answer. I am actually looking for a function to return the "URL" of the image and not the image itself. So I doubt if the_post_thumbnail is going to work for that. Or perhaps I am wrong?
- 0
- 2014-11-03
- theshorttree
-
@theshorttree voirma réponsemise àjour.@theshorttree see my updated answer.
- 0
- 2014-11-03
- SLH
-
Cela atotalementfonctionné,mercibeaucouppour votretempset votre réponse!That totally worked, thanks a lot for your time and reply!
- 0
- 2014-11-03
- theshorttree
-
- 2018-11-10
Unpeutard à lafête,
mais
get_the_post_thumbnail_url(null,'full');
faitexactement letravail,oùpleinpeut être remplacéparminiature,moyen,moyen_grand ougrand.A bit late to the party,
but
get_the_post_thumbnail_url(null,'full');
does exactly the job, where full can be replaced by thumbnail, medium, medium_large or large. -
- 2020-05-02
Pour ceux qui viendrontici après octobre 2019
WordPress aintroduit un "seuil degrandeimage" depuis la version 5.3 ( Lien )
Enbref,toutes lesimages au-dessus de 2560px seront réduites lors de l'importation. Appeler leformat d'image "complet"ne renverraplustoujours l'image d'origineintacte,maispourrait renvoyer cette version de 2560pixelset aura "-scaled" dans l'urlet le chemin.
Vouspouveztoujours obtenir l'urlet le chemin desimagestéléchargées à l'origine avec lesfonctions suivantes:
wp_get_original_image_path()
ouwp_get_original_image_url()
. Bien que la documentation suggère qu'unenouvelletaille"original_image"
ait été ajoutée,wp_get_attachment_image,wp_get_attachment_image_src ou desfonctions similaires renvoienttoujours la version réduite.Donc,pour autant queje sache,aucunmoyen d'obtenir les dimensions dufichier d'origine,etc.For those who are coming here post October 2019
WordPress has introduced a "Big Image Threshold" since version 5.3 (Link)
In short all images above 2560px will be downscaled on upload. Calling the image format "full" will no longer always return the original untouched image but might return that 2560px version and will have '-scaled' in the url and path.
You can still get the url and path of the originally uploaded images with the following functions:
wp_get_original_image_path()
orwp_get_original_image_url()
. Although the documentation suggests a new size"original_image"
was added, wp_get_attachment_image, wp_get_attachment_image_src or similar functions still return the scaled down version. So as far as I can tell no way to get the original file dimentions etc.
J'utilise actuellement le code suivantpour obtenir l'URL de l'image sélectionnée d'un article wordpress:
Mais le codene renvoie que laminiature lapluspetite (150x150px).Voici ce quej'obtiens:
Ma questionest la suivante: commentpuis-je luifaire renvoyer l'URL de l'image d'origine (imageen taille réelle) qui serait:
Mercibeaucouppour votretempset votre aide.