您的当前位置:首页 > 知识博客 > wordpress建站

WordPress获取附件URL函数:wp_get_attachment_url

时间:2024-03-11

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()


欢迎咨询/Welcome to inquire
tel/vx:18842938855
qq:1685522781
email:1685522781@qq.com

Copyright © 2019-2024 baidu.bond


Whatsapp
Powered by RRZCMS