come ottenere l'immagine originale usando wp_get_attachment_image_src
3 risposta
- voti
-
-
wp_get_attachment_image_src ($ PriImgId,'full') [0];daràil collegamentoesattowp_get_attachment_image_src($PriImgId, 'full')[0]; will give the exact link
- 2
- 2017-07-31
- Killer
-
-
- 2020-06-24
C'è wp_get_attachment_image_url introdottoin WordPress 4.4. 0. Accetta questi argomenti:
- int $ attachment_id - ID allegatoimmagine.
- string| array $ size - Facoltativo. Dimensioni dell'immagine da recuperare. Accetta qualsiasi dimensione dell'immagine valida o un array di valori di larghezzae altezzain pixel (in quest'ordine). "Miniatura"predefinita.
- bool $icon :facoltativo. Indica se l'immagine deveesseretrattata come un'icona. Falsopredefinito.
Restituisce
string
(URL completo dell'allegatoinclusoil dominio) ofalse
senon è statatrovata alcunaimmagine.Esempi di utilizzo:
$thumbnail = wp_get_attachment_image_url( $attachmentId, 'my-custom-size' ); $original = wp_get_attachment_image_url( $attachmentId, 'full' ); $square = wp_get_attachment_image_url( $attachmentId, [600, 600] );
Le dimensioni delleimmagini sonogeneralmente definitein functions.php deltuotema. La documentazione di WordPress copre questo aspettoin modo approfondito: Miniature deipost/Dimensioni delleminiature
Se un array di duenumeri (larghezzae altezza) vienepassato allafunzione,cerca ditrovaregli armadi corrispondenti alla dimensionepreservando leproporzioni.
Dietro le quinte utilizza image_get_intermediate_size pertrovare latagliapreferita.
There's wp_get_attachment_image_url introduced in WordPress 4.4.0. It takes these arguments:
- int $attachment_id - Image attachment ID.
- string|array $size - Optional. Image size to retrieve. Accepts any valid image size, or an array of width and height values in pixels (in that order). Default 'thumbnail'.
- bool $icon - Optional. Whether the image should be treated as an icon. Default false.
Returns
string
(full attachment URL including domain) orfalse
if no image was found.Example uses:
$thumbnail = wp_get_attachment_image_url( $attachmentId, 'my-custom-size' ); $original = wp_get_attachment_image_url( $attachmentId, 'full' ); $square = wp_get_attachment_image_url( $attachmentId, [600, 600] );
Image sizes are usually defined in functions.php of your theme. WordPress documentation covers this in depth: Post Thumbnails / Thumbnail Sizes
If an array of two numbers (width and height) is passed into the function, it tries to find the closets matching size while preserving the aspect ratio.
Under the hood it uses image_get_intermediate_size to find the preferred size.
-
Voglio ottenere l'immagine originale con la stessa larghezzae altezza del caricamento.
Lamiaimmagine originale è 630 * 370.
Usando la seguente chiamata difunzione ottengo unaminiatura di dimensioni 630 * 198.
Comeposso ottenerlo a 630 * 370