Obtendo o caminho de miniatura em vez de tag de imagem
-
-
As suasimagens sãoparte de umagaleria depostagem ou apenasincluídasnabiblioteca demídia?Are your images part of a post gallery or just included in the media library?
- 0
- 2010-12-01
- PNMG
-
Todos são anexados aposts - sãominiaturasparapostes.All are attached to posts - they are thumbnails to posts.
- 0
- 2010-12-01
- Sampson
-
4 respostas
- votos
-
- 2010-12-01
miniatura éessencialmente anexopara que vocêpossa se aproximar desse lado - ID depesquisa com
get_post_thumbnail_id()
e buscar dados comwp_get_attachment_image_src()
,assim:if (has_post_thumbnail()) { $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail_name'); echo $thumb[0]; // thumbnail url }
(fonte )
Thumbnail is essentially attachment so you can approach from that side - lookup ID with
get_post_thumbnail_id()
and fetch data withwp_get_attachment_image_src()
, like this:if (has_post_thumbnail()) { $thumb = wp_get_attachment_image_src(get_post_thumbnail_id(), 'thumbnail_name'); echo $thumb[0]; // thumbnail url }
(source)
-
- 2016-12-21
get_the_post_thumbnail_url($recent['ID']);
O acimafez otruqueparamim!Eutive que adivinhar afunçãoe émagicamentetrabalhado!
ébommencionar que usei
get_recent_posts
loopnoprocesso.get_the_post_thumbnail_url($recent['ID']);
The above did the trick for me! I had to guess the function and it magically worked!
Its is good to mention that I used
get_recent_posts
loop in the process. -
- 2010-12-01
Ummétodo seria convertertudo o que é retornado de
get_the_post_thumbnail ()
para um objetoe puxe o atributo src$thumbnail=novo simplexmlelement (get_the_post_thumbnail ($postid)); imprimir $thumbnail- > atributos () - > src;
One method would be to convert whatever is returned from
get_the_post_thumbnail()
to an object, and pull thesrc
attribute:$thumbnail = new SimpleXMLElement( get_the_post_thumbnail( $postid ) ); print $thumbnail->attributes()->src;
-
- 2010-12-01
Quandoeuprecisarexibir umaminiatura que é anexada a umagaleria depostagem,eu uso umafunçãopersonalizadaem minhasfunções.php. Pode sermaismatar suasnecessidades,mas deve cobrirtudo.
Nesteexemplo,recuperotodas asimagensnagaleria de umposte,em seguida,exiba cadaimagemem umitem de lista. A lista contém aimagemem miniaturaenvolvidaem uma âncora que se vincula àpostagem daimagem veio. A cadeia de saídapode serfacilmentepersonalizadapara suasnecessidades.
function get_gallery_image_thumb_list($size){ global $post; $args = array( 'numberposts' => null, 'post_parent' => $post->ID, 'post_type' => 'attachment', 'nopaging' => false, 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'post_status' => 'any' ); $attachments =& get_children($args); if ($attachments) { foreach($attachments as $attachment) { foreach($attachment as $attachment_key => $attachment_value) { $imageID = $attachment->ID; $imageTitle = $attachment->post_title; $imageCaption = $attachment->post_excerpt; $imageDescription = $attachment->post_content; $imageAlt = get_post_meta($imageID, '_wp_attachment_image_alt', true); $imageArray = wp_get_attachment_image_src($attachment_value, $size, false); $imageURI = $imageArray[0]; // 0 is the URI $imageWidth = $imageArray[1]; // 1 is the width $imageHeight = $imageArray[2]; // 2 is the height // Build the <img> string $ImgString = '<li><a href="' . get_permalink() . '" title="' . the_title("", "", false) . '"><img src="' . $imageURI . '" width="' . $imageWidth . '" height="' . $imageHeight . '" alt="' . $imageAlt . '" title="' . $imageTitle . '" /></a></li>'; // Print the image echo $ImgString; break; } } } unset($args);}
Então liguepara afunçãoe passenotamanho daimagem que você deseja retornada (miniatura,média,grande ou completa) como assim:
get_gallery_image_thumb_list("thumbnail");
Issoprecisará ser chamadono loop ouno looppersonalizado.
When I need to display a thumbnail that is attached to a post gallery, I use a custom function in my functions.php. It might be over kill for your needs, but it should cover everything.
In this example, I retrieve all the images in a post's gallery, and then display each image in a list item. The list contains the thumbnail image wrapped in an anchor that links to the post the image came from. The output string can easily be customized to your needs.
function get_gallery_image_thumb_list($size){ global $post; $args = array( 'numberposts' => null, 'post_parent' => $post->ID, 'post_type' => 'attachment', 'nopaging' => false, 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID', 'post_status' => 'any' ); $attachments =& get_children($args); if ($attachments) { foreach($attachments as $attachment) { foreach($attachment as $attachment_key => $attachment_value) { $imageID = $attachment->ID; $imageTitle = $attachment->post_title; $imageCaption = $attachment->post_excerpt; $imageDescription = $attachment->post_content; $imageAlt = get_post_meta($imageID, '_wp_attachment_image_alt', true); $imageArray = wp_get_attachment_image_src($attachment_value, $size, false); $imageURI = $imageArray[0]; // 0 is the URI $imageWidth = $imageArray[1]; // 1 is the width $imageHeight = $imageArray[2]; // 2 is the height // Build the <img> string $ImgString = '<li><a href="' . get_permalink() . '" title="' . the_title("", "", false) . '"><img src="' . $imageURI . '" width="' . $imageWidth . '" height="' . $imageHeight . '" alt="' . $imageAlt . '" title="' . $imageTitle . '" /></a></li>'; // Print the image echo $ImgString; break; } } } unset($args);}
Then call the function and pass in the size of image you want returned (thumbnail, medium, large or full) like so:
get_gallery_image_thumb_list("thumbnail");
This will need to be called in The Loop or a custom loop.
Eu vejomuitosmétodos demostrarminiaturasno WordPress,masnãotenho certeza de comoeupoderia obter apenas o caminhopara aminiatura de umpost,em vez do códigoprontoem HTMLgeradoporfunções como
the_post_thumbnail()
eget_the_post_thumbnail()
.Quaismétodosestão disponíveispara obter apenas o caminho daminiatura (para configurá-lo como um BGImage)em vez do
<img />
tag?Eu sótenho a opção de analisar os resultados dométodoget_
ouexiste umamaneiramaisfácil?