Como faço para obter o URL da imagem apenas no_post_thumbnail
-
-
Possível duplicado de [recebendo caminho deminiaturaem vez detag deimagem] (http://wordpress.stackexchange.com/questions/4745/getting-thumbnail-pather-tather-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 respostas
- votos
-
- 2011-02-12
Vocêtambémpodetentar:
Se vocêtiver apenas umaminiatura detamanho:
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ) );
ou ... Se vocêtiver váriostamanhos:
$thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), "size" );
Observação que wp_get_attachment_image_src () retorna umamatriz: URL,largura,altura,is_intermediate.
Então,se você quiser apenas o URL daimagem:
echo $thumbnail[0];
Recursos:
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:
-
Umapequena dica: Se vocêestiver usando wp_get_attachment_image_src () Função comtamanhoe deseja obter otamanhoexato daminiatura: Use onome daminiaturafornecidona definição (função add_image_size ()).Se você usar o Array com Dimensions WP usará oprimeirotamanho daimagem quetenha largura ou altura adequada.Então vocêpode obter umaimagemerrada.Exemplo: Em vez de 156x98,vocêpodeter 120x98 setiver 2imagens definidas: 156x98e 120x98 (altura é amesma).Eu caípor uma vez;)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
Issofaz otruque:
<?php wp_get_attachment_image_src('subgall-thumb'); ?>
Certifique-se de usar onome corretopara aminiatura que vocêestá ligando.
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.
-
Eunão sei seissomudou desde 2012,masem 2017 oprimeiroparâmetro de `wp_get_attachment_image_src` deve ser onúmero deidentificação de anexo,não otamanho.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
Desde o WordPress 4.4,há umafunção centraleficiente quepode lidar comisso deformamais limpa do que as respostas aqui.
Vocêpode usar
the_post_thumbnail_url( $size )
QuaisImprima o URL dapós-miniatura.Alternativamente se você quiser retornar o URLem vez deenviá-loimediatamente,vocêpode usar
$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
oktem usando
simplexml_load_string
$dom = simplexml_load_string(get_the_post_thumbnail()); $src = $dom->attributes()->src; echo $src;
Outrométodo ébem-vindo.
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
Porfavor,use o código abaixo
<?php get_the_post_thumbnail_url(); ?>
senãofor suficientepara atingir seu objetivo,tente abaixo do código
<?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
para um rápido & amp; Solução suja,tapaissono arquivofunctions.php do seutema
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); }
usado dentro do loop,isso lhe dará o que vocêestáprocurando
.
Isso retornará algo como 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="');
.
* "dentro do loop"=Procurepor algo comoenquanto (tem_posts ()):the_post ();
** Vocêtambémpode sub out "pós-grande " com qualquer um dessestamanhos deimagempredefinidos: pós-miniatura, pós-médio, Post-completo
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
-
isso é ruim.Por que você usatodas as capspara seus códigos?that's bad. why do you use all caps for your codes?
- 0
- 2020-06-03
- Raptor
Eu quero saber como obter URL deimagemem
the_post_thumbnail()
padrão
the_post_thumbnail()
Aquieu queropegar apenas o SRC.Comofaçofiltro
the_post_thumbnail()
apenaspara obterhttp://domain.com/wp-content/uploads/2011/02/book06.jpg
Deixe-me saber