wordpress获取特色图片地址

function get_attachment($size, $id)
{
    if (empty($size)) {
        $size = ‘medium’;
    }
    $output = ”;
    if (has_post_thumbnail($id)) {
        $output = wp_get_attachment_image_url(get_post_thumbnail_id($id), $size);
    } else {
        $attachments = get_posts(array(
            ‘post_type’ => ‘attachment’,
            ‘numberposts’ => 1,
            ‘post_parent’ => $id,
            ‘post_mime_type’ => ‘image’,
        ));
        if (!empty($attachments)) {
            $output = wp_get_attachment_image_url($attachments[0]->ID, $size);
        } else {
            $output = get_template_directory_uri() . ‘/assets/img/default.jpg’;
        }
    }
    return $output;
}