【问题标题】:How can I get the image url in WordPress?如何在 WordPress 中获取图片网址?
【发布时间】:2014-06-25 13:06:09
【问题描述】:

我正在使用此代码将所有图像上传到页面,它工作正常,但我想将图像 URL 用于灯箱功能,目前我得到一个 img 对象。有什么办法可以专门获取图片网址吗?我想认为它是数组的一部分。这是我正在使用的代码:

<?php
    $images = get_children( array(
    'post_parent' => $post->ID, 
    'post_type' => 'attachment', 
    'post_mime_type' => 'image', 
    'orderby' => 'menu_order', 
    'order' => 'ASC', 
    'numberposts' => 999 ) ); 
    if ( $images ) { 
        //looping through the images
        foreach ( $images as $attachment_id => $attachment ) {
        ?>
<li>
<a href="*the_img_url*" data-lightbox="lightbox-1" data-title="<?php echo $attachment->post_excerpt; ?>" ><?php echo wp_get_attachment_image( $attachment_id, 'full' ); ?>
</a>
</li>
<?php
}
}
?>

谢谢。

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    你试过了吗

    <?php echo wp_get_attachment_url( $attachment_id ); ?>  
    // $attachment_id is  The ID of the desired attachment 
    

    【讨论】:

    • 谢谢,这完美!我会尽快接受你的回答。享受你的一天
    猜你喜欢
    • 1970-01-01
    • 2011-03-16
    • 2012-09-27
    • 2018-07-21
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多