Cómo conseguir WordPress post destacado url de la imagen


Estoy usando esta función para obtener las imágenes destacadas

<a href="#" rel="prettyPhoto">
<?php the_post_thumbnail('thumbnail'); ?>
</a>

Ahora quiero obtener la imagen completa al hacer clic en la etiqueta de anclaje para la que necesito una url de imagen destacada en

<a href="here" rel="prettyPhoto">

Por favor ayuda

Author: ManpreetSandhu, 2012-06-29

17 answers

Compruebe el código a continuación y hágame saber si funciona para usted.

<?php if (has_post_thumbnail( $post->ID ) ): ?>
  <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
  <div id="custom-bg" style="background-image: url('<?php echo $image[0]; ?>')">

  </div>
<?php endif; ?>
 238
Author: swapnesh,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-07-29 18:56:30

Si desea SOLO la fuente, y no una matriz con otra información:

<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID), 'thumbnail' ); ?>
<img src="<?php echo $url ?>" />

 

 87
Author: LOLapalooza,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-05-20 21:12:12
// Try it inside loop.  
<?php
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
echo $feat_image;
?>
 15
Author: Omprakash Patel,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-11-18 07:16:36

Manera fácil!

 <?php 
     wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()))
 ?>
 10
Author: Luis Felipe Barnett V,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-07 17:18:23

Esto funcionó perfectamente para mí:

<?php echo get_the_post_thumbnail_url($post_id, 'thumbnail'); ?>
 9
Author: maxim,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-03-04 03:27:15

Hola creo que esta es la solución más fácil y la actualizada;

<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>
 6
Author: Fredrick Boaz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-09-19 15:53:52

Puedes probar esto:

<?php 
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); 
echo $feat_image; 
?>
 4
Author: nim,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-06-16 07:16:29

Esta es la respuesta más simple. <?php $img = get_the_post_thumbnail_url($postID,'post-thumbnail' ); ?>

 4
Author: Vishwajeet Mishra,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-04 05:11:49

Prueba este

<?php echo get_the_post_thumbnail($post_id, 'thumbnail', array('class' => 'alignleft')); ?>

 3
Author: yahya akhtar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-02-26 13:15:57

También puede usar para obtener la url de los archivos adjuntos de imágenes de la siguiente manera. Funciona bien.

if ( has_post_thumbnail() ) {
 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ),  'medium' ); 
}
 3
Author: farhan,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-13 15:28:08

También puedes obtenerlo de post_meta así:

echo get_post_meta($post->ID, 'featured_image', true);
 3
Author: Dhyey,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-24 14:06:49

Puedes probar esto.

<?php
   $image_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<a href="<?php echo $image_url; ?>" rel="prettyPhoto">
 2
Author: Jakir Hossain,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-20 16:13:16
<?php
    if (has_post_thumbnail( $post->ID ) ):
        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' );
?>
        <img src="<?php echo $image[0]; ?>">  
<?php endif; ?>
 1
Author: Dhruvin Moradiya,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-21 06:52:00

Probarás esto

<?php $url = wp_get_attachment_url( get_post_thumbnail_id($post->ID),'full' ); ?>//Here you can manage your image size like medium,thumbnail or custom size
 <img src="<?php echo $url ?>" />
 1
Author: Viral M,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-12-06 06:34:37

También puede usar para obtener la url de los archivos adjuntos de imágenes de la siguiente manera:

<?php
"<div><a href=".get_permalink(id).">".wp_get_attachment_url(304, array(50,50), 1)."</a></div>";
?>
 0
Author: user3615759,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-05-08 09:35:15
<img src="<?php echo get_post_meta($post->ID, "mabp_thumbnail_url", true); ?>" alt="<?php the_title(); ?>" width ="100%" height ="" />
 -1
Author: Al3abMizo Games,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-05 13:17:58
 <?php $image_src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_size' );

 $feature_image_url = $image_src[0]; ?>

Puede cambiar el valor thumbnail_size según su tamaño requerido.

 -2
Author: Mohammad Farhan Atif Wattoo,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2018-01-05 06:48:08