function sf_download_list_shortcode($atts) { $html = '
'; for ($i = 1; $i <= 20; $i++) { $g = get_field("download_{$i}"); if (!$g) continue; /* ▼ ACF 値取得 */ $title = isset($g['acf-title']) ? trim($g['acf-title']) : ''; // 説明文 $label = isset($g['acf-label']) ? trim($g['acf-label']) : ''; // ファイル名(拡張子あり) $raw_file = isset($g['acf-file']) ? $g['acf-file'] : ''; $color_num = isset($g['acf-color']) ? intval($g['acf-color']) : 0; if (!$title || !$label || !$raw_file) continue; /* ▼ ファイルURL */ $file_url = is_array($raw_file) ? $raw_file['url'] : (is_numeric($raw_file) ? wp_get_attachment_url($raw_file) : $raw_file); if (!$file_url) continue; /* ▼ 拡張子 */ $ext = strtolower(pathinfo($file_url, PATHINFO_EXTENSION)); /* ▼ SVG(download-list の既存関数を使用) */ if (in_array($ext, ['xls','xlsx'])) { $svg = sf_svg_excel(); } elseif (in_array($ext, ['doc','docx'])) { $svg = sf_svg_word(); } elseif ($ext === 'pdf') { $svg = sf_svg_pdf(); } elseif ($ext === 'zip') { $svg = sf_svg_zip(); } elseif (in_array($ext, ['jpg','jpeg','png'])) { $svg = sf_svg_img(); } else { $svg = sf_svg_file(); } /* ▼ 色クラス(color-1〜6) */ $color_class = ($color_num >= 1 && $color_num <= 6) ? 'color-' . $color_num : 'color-6'; /* ▼ ボタン生成 */ $html .= ''; $html .= '
'.$svg.'
'; $html .= '
'; $html .= '
'.esc_html($title).'
'; // acf-title $html .= '
'.esc_html($label).'
'; // acf-label $html .= '
'; $html .= '
'; } $html .= '
'; return str_replace(["\r","\n","\t"], '', $html); } add_shortcode('sf_download_list', 'sf_download_list_shortcode'); サウスフロントタワー町田 住宅部会

サウスフロントタワー町田 住宅部会