如何获得WordPress贴子的特色图片url

时间:2021-11-28 06:58:43

I am using a this function to get the featured images

我正在使用这个函数来获取有特色的图像

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

now i want to get the full featured image on click on anchor tag for which i need a featured image url in

现在我想要在锚点标签上获得完整的特征图像,我需要一个特征图像url

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

please help

请帮助

17 个解决方案

#1


223  

Check the code below and let me know if it works for you.

检查下面的代码,让我知道它是否适合你。

<?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; ?>

#2


86  

If you want JUST the source, and not an array with other information:

如果您只想要源代码,而不是包含其他信息的数组:

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

 

 

#3


13  

// Try it inside loop.  
<?php
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
echo $feat_image;
?>

#4


9  

Easy way!

简单的方法!

 <?php 
     wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()))
 ?>

#5


9  

This perfectly worked for me:

这对我来说非常有用:

<?php echo get_the_post_thumbnail_url($post_id, 'thumbnail'); ?>

#6


5  

hi i think this is the most easiest solution and the updated one;

大家好,我认为这是最简单的解决方案和最新的方案;

<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>

#7


4  

You can try this:

你可以试试这个:

<?php 
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); 
echo $feat_image; 
?>

#8


3  

Try this one

试试这个

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

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

#9


3  

You can also use for getting the url for image attachments as follows. It works fine.

您还可以使用以下方法获取图像附件的url。它将正常工作。

if ( has_post_thumbnail() ) {
 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ),  'medium' ); 
}

#10


3  

This is the most simplest answer. <?php $img = get_the_post_thumbnail_url($postID,'post-thumbnail' ); ?>

这是最简单的答案。< ?php $img = get_the_post_thumbnail_url($postID,'post- thumbnail_url ');? >

#11


3  

You can also get it from post_meta like this:

你也可以从post_meta得到如下:

echo get_post_meta($post->ID, 'featured_image', true);

#12


2  

You can try this.

你可以试试这个。

<?php
   $image_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<a href="<?php echo $image_url; ?>" rel="prettyPhoto">

#13


1  

<?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; ?>

#14


1  

You will try this

你会尝试这个

<?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 ?>" />

#15


0  

you can also use for getting the url for image attachments as follows:

您还可以使用以下的url获取图像附件:

<?php
"<div><a href=".get_permalink(id).">".wp_get_attachment_url(304, array(50,50), 1)."</a></div>";
?>

#16


-1  

<img src="<?php echo get_post_meta($post->ID, "mabp_thumbnail_url", true); ?>" alt="<?php the_title(); ?>" width ="100%" height ="" />

#17


-2  

 <?php $image_src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_size' );

 $feature_image_url = $image_src[0]; ?>

You can change thumbnail_size value as per your require size.

您可以根据需要的大小更改thumbnail_size值。

#1


223  

Check the code below and let me know if it works for you.

检查下面的代码,让我知道它是否适合你。

<?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; ?>

#2


86  

If you want JUST the source, and not an array with other information:

如果您只想要源代码,而不是包含其他信息的数组:

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

 

 

#3


13  

// Try it inside loop.  
<?php
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
echo $feat_image;
?>

#4


9  

Easy way!

简单的方法!

 <?php 
     wp_get_attachment_url(get_post_thumbnail_id(get_the_ID()))
 ?>

#5


9  

This perfectly worked for me:

这对我来说非常有用:

<?php echo get_the_post_thumbnail_url($post_id, 'thumbnail'); ?>

#6


5  

hi i think this is the most easiest solution and the updated one;

大家好,我认为这是最简单的解决方案和最新的方案;

<?php the_post_thumbnail( 'single-post-thumbnail' ); ?>

#7


4  

You can try this:

你可以试试这个:

<?php 
$feat_image = wp_get_attachment_url( get_post_thumbnail_id($post->ID) ); 
echo $feat_image; 
?>

#8


3  

Try this one

试试这个

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

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

#9


3  

You can also use for getting the url for image attachments as follows. It works fine.

您还可以使用以下方法获取图像附件的url。它将正常工作。

if ( has_post_thumbnail() ) {
 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ),  'medium' ); 
}

#10


3  

This is the most simplest answer. <?php $img = get_the_post_thumbnail_url($postID,'post-thumbnail' ); ?>

这是最简单的答案。< ?php $img = get_the_post_thumbnail_url($postID,'post- thumbnail_url ');? >

#11


3  

You can also get it from post_meta like this:

你也可以从post_meta得到如下:

echo get_post_meta($post->ID, 'featured_image', true);

#12


2  

You can try this.

你可以试试这个。

<?php
   $image_url = wp_get_attachment_url( get_post_thumbnail_id($post->ID) );
?>
<a href="<?php echo $image_url; ?>" rel="prettyPhoto">

#13


1  

<?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; ?>

#14


1  

You will try this

你会尝试这个

<?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 ?>" />

#15


0  

you can also use for getting the url for image attachments as follows:

您还可以使用以下的url获取图像附件:

<?php
"<div><a href=".get_permalink(id).">".wp_get_attachment_url(304, array(50,50), 1)."</a></div>";
?>

#16


-1  

<img src="<?php echo get_post_meta($post->ID, "mabp_thumbnail_url", true); ?>" alt="<?php the_title(); ?>" width ="100%" height ="" />

#17


-2  

 <?php $image_src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'thumbnail_size' );

 $feature_image_url = $image_src[0]; ?>

You can change thumbnail_size value as per your require size.

您可以根据需要的大小更改thumbnail_size值。