WordPress获取附件URL函数:wp_get_attachment_url

WordPress函数wp_get_attachment_url用于获取附件的URL。

wp_get_attachment_url( int $attachment_id )

函数参数

$attachment_id

整数

附件的ID

函数返回值

wp_get_attachment_url()函数返回指定附件的URL地址。

函数使用示例

if(have_posts() ) : while ( have_posts()) : the_post();
    if(has_post_thumbnail()) {
        $feat_image_url = wp_get_attachment_url(get_post_thumbnail_id());
        echo '<div style="background-image:url('.$feat_image_url.');"></div>';
    }
    endwhile;
endif;

扩展阅读

wp_get_attachment_url()函数位于:wp-includes/post.php

相关函数:

  • wp_get_upload_dir()
  • wp_get_attachment_relative_path()
  • wp_basename()
阿里云