Come ottengo l'URL dell'immagine solo su the_post_thumbnail
-
-
possibile duplicato di [Recupero delpercorso delleminiature anziché deltagimmagine] (http://wordpress.stackexchange.com/questions/4745/getting-thumbnail-path-rather-than-image-tag)possible duplicate of [Getting Thumbnail Path rather than Image Tag](http://wordpress.stackexchange.com/questions/4745/getting-thumbnail-path-rather-than-image-tag)
- 0
- 2011-02-12
- Jan Fabry
-
6 risposta
- voti
-
- 2011-02-12
Potresti ancheprovare:
Se hai solo unaminiatura di dimensioni:
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) );
Oppure ... se haipiù dimensioni:
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "size" );
Nota che wp_get_attachment_image_src () restituisce un array: url,width,height,is_intermediate.
Quindi,se desideri solo l'URL dell'immagine:
echo $thumbnail[0];
Risorse:
You might also try:
If you only have one size thumbnail:
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) );
Or...if you have multiple sizes:
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "size" );
Note that wp_get_attachment_image_src() returns an array: url, width, height, is_intermediate.
So if you just want only the image url:
echo $thumbnail[0];
Resources:
-
Unpiccolo suggerimento: se stai usando lafunzione wp_get_attachment_image_src () con la dimensionee vuoi ottenere la dimensioneesatta dellaminiatura: usailnome dellaminiaturafornitonella definizione (funzione add_image_size ()).Se si utilizza un array con dimensioni,WP utilizzerà laprima dimensione dell'immagine con larghezza o altezza adeguate.Quindipotresti ottenere un'immagine sbagliata.Esempio:invece di 156x98potresti avere 120x98 se hai 2immagini definite: 156x98e 120x98 (l'altezza è la stessa).Ci sono caduto una volta;)A little hint: if you are using wp_get_attachment_image_src() function with size and want to get exact thumbnail size: use thumbnail name given in definition (function add_image_size()). If you use array with dimensions WP will use first image size that have proper width or height. So you may get wrong image. Example: instead of 156x98 you might have got 120x98 if you have 2 images defined: 156x98 & 120x98 (height is the same). I fell for it once ;)
- 0
- 2011-10-16
- Marek Tuchalski
-
- 2012-12-21
Questofailtrucco:
<?php wp_get_attachment_image_src('subgall-thumb'); ?>
Assicurati di utilizzareilnome correttoper laminiatura che stai chiamando.
This does the trick:
<?php wp_get_attachment_image_src('subgall-thumb'); ?>
Make sure you use the correct name for the thumbnail that you are calling.
-
Non so se questo sia cambiato dal 2012,manel 2017ilprimoparametro di `wp_get_attachment_image_src` deveessereilnumero ID allegato,non la dimensione.I don't know if this has changed since 2012, but in 2017 the first parameter of `wp_get_attachment_image_src` must be the attachement id number, not the size.
- 1
- 2017-05-11
- squarecandy
-
- 2017-09-15
Apartire da WordPress 4.4,esiste unafunzione dibaseefficientein grado digestirloin modopiùpulito rispetto alle risposte qui.
Puoi utilizzare
the_post_thumbnail_url ($ size)
chestampa l'URL dellaminiatura delpost.In alternativa,se desideri restituire l'URLinvece di visualizzarloimmediatamente,puoi utilizzare
$ url=get_the_post_thumbnail_url ($post_id,$ size) Since WordPress 4.4, there's an efficient core function that can handle this in a cleaner way than the answers here.
You can use
the_post_thumbnail_url( $size )
which will print the URL of the post thumbnail.Alternatively if you want to return the URL instead of immediately output it, you can use
$url = get_the_post_thumbnail_url( $post_id, $size )
-
- 2011-02-12
Ok capito utilizzando
simplexml_load_string
$dom = simplexml_load_string(get_the_post_thumbnail()); $src = $dom->attributes()->src; echo $src;
Un altrometodo èilbenvenuto.
Ok got it using
simplexml_load_string
$dom = simplexml_load_string(get_the_post_thumbnail()); $src = $dom->attributes()->src; echo $src;
Another method are welcome.
-
- 2018-10-26
Utilizzail codice seguente
<?php get_the_post_thumbnail_url(); ?>
Senon è sufficienteper raggiungereiltuo obiettivo,provail codice seguente
<?php $postimages = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'large' ); // Check for images if ( $postimages ) { // Get featured image $postimage = $postimages[0]; } else {} while (have_posts() && $i < 8) : the_post(); echo esc_url( $postimage ); ?>
Please Use the below code
<?php get_the_post_thumbnail_url(); ?>
If It's not enough to achieve your goal then try below code
<?php $postimages = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), 'large' ); // Check for images if ( $postimages ) { // Get featured image $postimage = $postimages[0]; } else {} while (have_posts() && $i < 8) : the_post(); echo esc_url( $postimage ); ?>
-
- 2019-02-17
Per un rapido & amp; soluzione sporca,inseriscilonelfilefunctions.php deltuotema
FUNCTION GET_STRING_BETWEEN($STRING, $START, $END){ $STRING = " ".$STRING; $INI = STRPOS($STRING, $START); IF ($INI == 0) RETURN ""; $INI += STRLEN($START); $LEN = STRPOS($STRING, $END, $INI) - $INI; RETURN SUBSTR($STRING, $INI, $LEN); }
Utilizzato all'interno del ciclo,questoti darà quello che stai cercando
Questo restituirà qualcosa come http://foo.com/wp-content/uploads/2019/02/toy-story-two-was-ok.jpg
$THE_FEATURED_IMAGE = GET_STRING_BETWEEN(get_the_post_thumbnail(NULL,'post-large'), 'src="', '" class="');
* "Withinthe loop"=cerca qualcosa come while (have_posts ()):the_post ();
** Puoi anche sottotitolare "post-large " con una qualsiasi di queste dimensioni diimmaginepredefinite: post-miniatura, post-media, post-full
For a quick & dirty solution, slap this in the functions.php file of your theme
FUNCTION GET_STRING_BETWEEN($STRING, $START, $END){ $STRING = " ".$STRING; $INI = STRPOS($STRING, $START); IF ($INI == 0) RETURN ""; $INI += STRLEN($START); $LEN = STRPOS($STRING, $END, $INI) - $INI; RETURN SUBSTR($STRING, $INI, $LEN); }
Used within the loop, this will give you what you're looking for
This will return something like http://foo.com/wp-content/uploads/2019/02/toy-story-two-was-ok.jpg
$THE_FEATURED_IMAGE = GET_STRING_BETWEEN(get_the_post_thumbnail(NULL,'post-large'), 'src="', '" class="');
* "Within the loop" = look for something like while ( have_posts() ) : the_post();
**You can also sub out "post-large" with any of these predefined image sizes : post-thumbnail, post-medium, post-full
-
questo èmale.perché usituttomaiuscoloperi tuoi codici?that's bad. why do you use all caps for your codes?
- 0
- 2020-06-03
- Raptor
Voglio sapere come ottenere l'URL dell'immagine su
the_post_thumbnail()
Predefinito
the_post_thumbnail()
Qui voglioprendere solo l'src.Comefaccio afiltrare
the_post_thumbnail()
soloper ottenerehttp://domain.com/wp-content/uploads/2011/02/book06.jpg
Fammi sapere