编辑文件:cb-carousel.php
<?php /** * Homepage carousel partial — standalone banner, sits between the header and * the static cb-hero (see front-page.php). * * Renders admin-managed carousel_slide posts as a carousel. Each slide = * background image (Featured Image) + headline (title) + subtitle (excerpt) + * an optional CTA (clothb2b_slide_cta meta). Zero published slides → this * partial outputs nothing and the hero below stands on its own. * * Behavior (fade, autoplay, dots, swipe) is in assets/js/hero-carousel.js, * mounted on .cb-carousel. The h1 is reserved for cb-hero; slide titles use h2/h3. * * @package ClothB2B_Child */ if ( ! defined( 'ABSPATH' ) ) { exit; } $slides = function_exists( 'clothb2b_hero_slides' ) ? clothb2b_hero_slides() : array(); if ( empty( $slides ) ) { return; } ?> <section class="cb-carousel" data-slide-label="<?php esc_attr_e( 'Slide', 'clothb2b' ); ?>" aria-roledescription="carousel"> <div class="cb-carousel__track"> <?php foreach ( $slides as $i => $slide ) : $bg = get_the_post_thumbnail_url( $slide->ID, 'full' ); $title = get_the_title( $slide->ID ); $sub = $slide->post_excerpt; $cta = get_post_meta( $slide->ID, 'clothb2b_slide_cta', true ); $cta_label = ( is_array( $cta ) && ! empty( $cta['label'] ) ) ? $cta['label'] : ''; $cta_url = ( is_array( $cta ) && ! empty( $cta['url'] ) ) ? $cta['url'] : ''; $is_first = ( 0 === $i ); $tag = $is_first ? 'h2' : 'h3'; // h1 reserved for cb-hero below. ?> <div class="cb-carousel__slide<?php echo $is_first ? ' is-active' : ''; ?>" style="background-image:url('<?php echo esc_url( $bg ); ?>');"<?php echo $is_first ? '' : ' aria-hidden="true"'; ?>> <div class="cb-carousel__inner"> <div class="cb-carousel__content"> <?php if ( $title ) : ?> <<?php echo $tag; ?> class="cb-carousel__title"><?php echo esc_html( $title ); ?></<?php echo $tag; ?>> <?php endif; ?> <?php if ( $sub ) : ?> <p class="cb-carousel__sub"><?php echo esc_html( $sub ); ?></p> <?php endif; ?> <?php if ( $cta_label && $cta_url ) : ?> <a class="cb-btn cb-btn--light" href="<?php echo esc_url( $cta_url ); ?>"><?php echo esc_html( $cta_label ); ?></a> <?php endif; ?> </div> </div> </div> <?php endforeach; ?> </div> <div class="cb-carousel__dots" role="tablist" aria-label="<?php esc_attr_e( 'Carousel slides', 'clothb2b' ); ?>"></div> <button type="button" class="cb-carousel__arrow cb-carousel__arrow--prev" aria-label="<?php esc_attr_e( 'Previous slide', 'clothb2b' ); ?>"> <svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true" focusable="false"><path d="M15 6l-6 6 6 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg> </button> <button type="button" class="cb-carousel__arrow cb-carousel__arrow--next" aria-label="<?php esc_attr_e( 'Next slide', 'clothb2b' ); ?>"> <svg viewBox="0 0 24 24" width="22" height="22" aria-hidden="true" focusable="false"><path d="M9 6l6 6-6 6" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg> </button> </section> <?php wp_reset_postdata();
保存
返回