幻灯片脚本前端获取函数(更新)
wptutor
2024-08-11
18 Views
function fetch_slider_images($slider_id) {
$slider_data = get_post_meta($slider_id, 'custom_slider', true);
$images = array();
if (!empty($slider_data) && is_array($slider_data)) {
foreach ($slider_data as $slide) {
if (!empty($slide['id'])) {
$image_url = wp_get_attachment_image_url($slide['id'], 'full');
if ($image_url) {
$images[] = array(
'url' => $image_url,
'title' => isset($slide['title']) ? $slide['title'] : '',
'caption' => isset($slide['caption']) ? $slide['caption'] : '',
'link' => isset($slide['link']) ? $slide['link'] : ''
);
}
}
}
}
return $images;
}