<?php
/**
 * Voices Section (Dynamic Loop)
 * 管理画面の「受講生の声」から複数のデータを取得して表示する
 */

// 「受講生の声」を取得する条件設定
$args = array(
    'post_type'      => 'sake_voice', // ←【修正】正しいデータ名（スラッグ）に変更しました！
    'posts_per_page' => -1,           // -1にすると登録されている全件（現在19件）を表示します。（10件などに制限も可能）
    'post_status'    => 'publish'
);
$voice_query = new WP_Query($args);
?>

<section id="voices" class="section">
    <div class="container">
        <div class="section-header">
            <h2 class="section-title">受講生の声</h2>
        </div>

        <div class="voice-marquee-container" style="display: flex; overflow-x: auto; gap: 20px; padding-bottom: 20px;">
            
            <?php if ( $voice_query->have_posts() ) : ?>
                <?php while ( $voice_query->have_posts() ) : $voice_query->the_post(); ?>
                    
                    <div class="voice-card-auto">
                        <h3 class="voice-quote">「<?php the_title(); ?>」</h3>
                        
                        <div class="voice-text" style="font-size: 0.95rem; line-height: 1.8; color: #555; margin-bottom: 15px;">
                            <?php 
                                // 本文を出力します。長すぎる場合は適宜カットします
                                echo wp_trim_words( wp_strip_all_tags( get_the_content() ), 80, '...' ); 
                            ?>
                        </div>
                        
                        <div class="voice-meta">
                            <?php 
                            // 抜粋（Excerpt）に入力されている属性情報を出力
                            if ( has_excerpt() ) {
                                echo get_the_excerpt();
                            }
                            ?>
                        </div>
                    </div>

                <?php endwhile; ?>
                <?php wp_reset_postdata(); ?>
            <?php else : ?>
                <p style="text-align:center;">【テスト】受講生の声はまだありません。</p>
            <?php endif; ?>

        </div>
    </div>
</section>