Funktion zum Abrufen der URL des hochgeladenen Originalbilds - in voller Größe
3 Antworten
- Stimmen
-
- 2014-11-03
In den WordPress-Kern sind viergültige Größenintegriert.
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)
Der letzteisteiner,den Sie suchen.
Im Folgenden wird die URL zurückgegeben.
<?php $src = wp_get_attachment_image_src( $attachment_id, $size, $icon ); echo $src[0];
Dergesamte Code kannfolgendermaßen aussehen:
<?php $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full', false ); echo $src[0]; // the url of featured image
Weitere Informationenfinden Sie hier .
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.
-
Dankefür deine Antwort.Ich suchetatsächlichnacheiner Funktion,um die "URL" des Bildes undnicht das Bild selbst zurückzugeben.Ichbezweifle also,dassthe_post_thumbnail dafürfunktionieren wird.Oder vielleichtirreichmich?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 siehemeine aktualisierte Antwort.@theshorttree see my updated answer.
- 0
- 2014-11-03
- SLH
-
Das hattotalgeklappt,vielen Dankfür deine Zeit und Antwort!That totally worked, thanks a lot for your time and reply!
- 0
- 2014-11-03
- theshorttree
-
- 2018-11-10
Einbisschen zu spät zur Party,
aber
get_the_post_thumbnail_url(null,'full');
erledigtgenau den Job,bei demfull durchthumbnail,medium,medium_large oder largeersetzt werden kann.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
Für diejenigen,dienach Oktober 2019 hierher kommen
WordPress hat seit Version 5.3einen "Big Image Threshold"eingeführt ( Link )
Kurzgesagt,alle Bilder über 2560px werdenbeim Hochladen verkleinert. Wenn Sie das Bildformat "voll"nennen,wirdnichtmehrimmer das ursprüngliche unberührte Bild zurückgegeben,sondernmöglicherweise die 2560px-Version. Die URL und der Pfad sind "skaliert".
Sie können weiterhin die URL und den Pfad der ursprünglich hochgeladenen Bildermit denfolgenden Funktionen abrufen:
wp_get_original_image_path()
oderwp_get_original_image_url()
. Obwohlin der Dokumentation vorgeschlagen wird,dasseine neue Größe"original_image"
hinzugefügt wurde,geben wp_get_attachment_image,wp_get_attachment_image_src oder ähnliche Funktionenimmernoch die verkleinerte Version zurück.Soweitich dasbeurteilen kann,gibt es keine Möglichkeit,die ursprünglichen Dateidimensionen usw. zuerhalten.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.
Ich verwende derzeit denfolgenden Code,um die URL des vorgestellten Bildeseines WordPress-Posts abzurufen:
Der Codegibt jedochnur die kleinere Miniaturansicht (150 x 150 Pixel) zurück.Folgendesbekommeich:
Meine Frageist,wieich die URLfür das Originalbild (Bildin voller Größe) zurückgeben kann.
Vielen Dankfür Ihre Zeit und Ihre Hilfe.