小编Alf*_*azo的帖子

Wordpress获取图片网址(目前使用wp_get_attachment_url)

在wordpress中获取图像附件网址时遇到一些麻烦.到目前为止这是我的代码:

<?php // find images attached to this post / page.
            global $post;
            $thumb_ID = get_post_thumbnail_id( $post->ID );
            $args = array(
                'post_type' => 'attachment',
                'post_mime_type' => 'image',
                'numberposts' => -1,
                'orderby' => 'menu_order',
                'order' => 'ASC',
                'exclude' => $thumb_ID,
                'post_parent' => $post->ID
            );
            $images = get_posts($args);
            ?>

            <?php // Loop through the images and show them

            if($images)
            {
            foreach($images as $image)  
            {

            echo  wp_get_attachment_image_url($image->ID, $size='attached-image');

            }
            }

?>
Run Code Online (Sandbox Code Playgroud)

什么都不返回.如果我换出wp_get_attachment_image_url($image->ID, $size='attached-image');wp_get_attachment_image($image->ID, $size='attached-image');这工作得很好,但在图像中带来的,而不是仅仅的URL.

url wordpress image attachment

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

attachment ×1

image ×1

url ×1

wordpress ×1