wordpress
画像のIDからURLを返す
function getImage($attachment_id){
if (empty($attachment_id)){
return false;
}
if ($attachment_id){
$image_attributes = wp_get_attachment_image_src($attachment_id, "large");
return $image_attributes[0];
}
return false;
}
記事IDから画像URLを返す
function getThumbnailUrl($post_id, $no_empty = false){
$empty_image = "/img/empty_image.jpg";
if ($post_id){
if ($image_id = get_post_thumbnail_id($post_id)){
return getImage($image_id);
}
}
if ($no_empty){
return false;
}
return $empty_image;
}