get_the_post_thumbnail_url()

最后更新于:2021-11-27 02:35:22

get_the_post_thumbnail_url( int|GC_Post$post=null, string|int[]$size=’post-thumbnail’)

响应 the post thumbnail URL.

参数

$post

(int|GC_Post) (Optional) Post ID or GC_Post object. Default is global $post.

Default value: null

$size

(string|int[]) (Optional) Registered image size to retrieve the source for or a flat array of height and width dimensions.

Default value: ‘post-thumbnail’

响应

(string|false) Post thumbnail URL or false if no image is available. If $size does not match any registered image size, the original image URL will be returned.

源文件

文件: gc-includes/post-thumbnail-template.php

function get_the_post_thumbnail_url( $post = null, $size = 'post-thumbnail' ) {
	$post_thumbnail_id = get_post_thumbnail_id( $post );

	if ( ! $post_thumbnail_id ) {
		return false;
	}

	return gc_get_attachment_image_url( $post_thumbnail_id, $size );
}
if ( have_posts() ) {
	while ( have_posts() ) {
		the_post();
 
		/* grab the url for the full size featured image */ 
		$featured_img_url = get_the_post_thumbnail_url('full'); 

		/* link thumbnail to full size image for use with lightbox*/ 
		echo '<a href="'.$featured_img_url.'" rel="lightbox">'; 
			the_post_thumbnail('thumbnail');
		echo '</a>';
	endwhile; 
endif; 
$thumbnail = get_the_post_thumbnail_url();

if ( $thumbnail ) {
	$alt_text = get_post_meta( $thumbnail->ID, '_gc_attachment_image_alt', true );

    if ( ! empty( $thumbnail ) ) {
		if ( ! empty( $alt_text ) ) {
			$alt_text = $alt_text;
       } else {
			$alt_text = __( 'no alt text set', 'textdomain' ); 
       }
	   echo '';
   }
}