admin管理员组文章数量:1279017
I'm trying to display the full size image of the single post from a custom post type that I created, below is what I've tried
<?php
$args = array(
'post_type' => 'press',
'order' => 'ASC',
'post_status' => 'publish',
'suppress_filters' => false
);
$press = new WP_Query( $args );
if ( $press->have_posts() ) { ?>
<?php while ( $press->have_posts() ) : $press->the_post(); ?>
<div class="col-sm-4 mb24">
<article class="post-article bg-white">
<div class="article-img">
<?php
if( has_post_thumbnail() ){
?>
<div class="img-box position-relative overflow-hidden">
<a href="<?php the_permalink(); ?>" class="height300 bg-graylight flex-center c-dark position-relative">
<img src="<?php echo get_the_post_thumbnail_url('full'); ?>" alt="<?php the_title(); ?>">
</a>
</div>
<?php } else { ?>
<a href="<?php the_permalink(); ?>" class="height300 bg-graylight flex-center c-dark position-relative">
<i class="ti-image font64"></i>
</a>
<?php } ?>
</div>
</article>
</div>
<?php endwhile; ?>
<?php } ?>
</div>
</div>
</section>
but seems this
get_the_post_thumbnail_url('full')
not working because it shows nothing e.g. src=""
but if I do
get_the_post_thumbnail_url()
surely gives me the image url but not the full size one. Any help, ideas please?
I'm trying to display the full size image of the single post from a custom post type that I created, below is what I've tried
<?php
$args = array(
'post_type' => 'press',
'order' => 'ASC',
'post_status' => 'publish',
'suppress_filters' => false
);
$press = new WP_Query( $args );
if ( $press->have_posts() ) { ?>
<?php while ( $press->have_posts() ) : $press->the_post(); ?>
<div class="col-sm-4 mb24">
<article class="post-article bg-white">
<div class="article-img">
<?php
if( has_post_thumbnail() ){
?>
<div class="img-box position-relative overflow-hidden">
<a href="<?php the_permalink(); ?>" class="height300 bg-graylight flex-center c-dark position-relative">
<img src="<?php echo get_the_post_thumbnail_url('full'); ?>" alt="<?php the_title(); ?>">
</a>
</div>
<?php } else { ?>
<a href="<?php the_permalink(); ?>" class="height300 bg-graylight flex-center c-dark position-relative">
<i class="ti-image font64"></i>
</a>
<?php } ?>
</div>
</article>
</div>
<?php endwhile; ?>
<?php } ?>
</div>
</div>
</section>
but seems this
get_the_post_thumbnail_url('full')
not working because it shows nothing e.g. src=""
but if I do
get_the_post_thumbnail_url()
surely gives me the image url but not the full size one. Any help, ideas please?
Share Improve this question asked Mar 5, 2019 at 13:01 Juliver GalletoJuliver Galleto 2903 gold badges6 silver badges14 bronze badges1 Answer
Reset to default 3The first argument for that function is not size. See the documentation (if a function's not working, checking the documentation should always be your first step):
get_the_post_thumbnail_url( int|WP_Post $post = null, string|array $size = 'post-thumbnail' )
The first argument is which post the get the URL for, while the size is the second argument.
To avoid redundancy, when you're in the loop, set the first argument to null
to get the current post:
<?php echo get_the_post_thumbnail_url( null, 'full' ); ?>
But honestly, you shouldn't be using this function this way. If you want to output the post thumbnail, use the the_post_thumbnail()
function. That way you automatically get the image's alt
text, width
and height
attributes, as well as srcset
and sizes:
<a href="<?php the_permalink(); ?>" class="height300 bg-graylight flex-center c-dark position-relative">
<?php the_post_thumbnail( 'full' ); ?>
</a>
本文标签: getthepostthumbnailurl(39full39) returns empty from custom post type
版权声明:本文标题:get_the_post_thumbnail_url('full') returns empty from custom post type 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741303520a2371233.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论