如何获得src链接到图像? (WordPress的)

时间:2014-12-18 16:04:25

标签: wordpress image src

我希望获得src链接到图片,但我没有获得指向附件页面的链接。

我在functions.php文件中使用此代码:

function show_all_thumbs() {
    global $post;
    $post = get_post($post);

/* image code */
$images =& get_children( 'post_type=attachment&post_mime_type=image&output=ARRAY_N&orderby=menu_order&order=ASC&post_parent='.$post->ID); 
if($images){
foreach( $images as $imageID => $imagePost ){

unset($the_b_img);
$the_b_img = wp_get_attachment_image($imageID, 'thumbnail', false);
$thumblist .= '<a target="_blank" href="'.get_attachment_link($imageID).'">'.$the_b_img.'</a>';

}
}
return $thumblist;
}

那么如何更改此行以获取src链接到图像:

<a target="_blank" href="'.get_attachment_link($imageID).'">

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

wp_get_attachment_image_src()返回一个数组,其中第一项包含src:

$src = wp_get_attachment_image_src( $imageID, 'thumbnail', false );

用法:

<a target="_blank" href="' . $src[0] . '">