WordPress函数:the_post_thumbnail_url 和 get_the_post_thumbnail_url

06月/12日/WordPress/浏览 240

WordPress中,the_post_thumbnail_url  和 get_the_post_thumbnail_url 用于获取文章缩略图路径。


参数可以是thumbnail, medium, large, full,或者通过函数 add_image_size() 自定义尺寸的关键字,比如:(32,32)。


用法参考:


<div class="post" style="background-image: url(<?php the_post_thumbnail_url(); ?>)"></div>


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; 

发表评论

暂无评论,抢个沙发...

客服 工单