向轮播添加 Alt 标签

Posted

技术标签:

【中文标题】向轮播添加 Alt 标签【英文标题】:Adding Alt Tags To Carousel 【发布时间】:2019-05-04 09:09:44 【问题描述】:

我正在尝试将 alt 标签添加到我网站上的自定义船轮播和船页。不知道我需要添加什么 php 以及放在哪里。轮播和页面上的图像都是缩略图。

我有boat_page.php 和boat_carousel.php,这是我认为需要添加代码的地方。

不确定我是否应该将所有代码添加到这篇文章中。

这是指向页面https://www.embarkboathire.com.au/boats/的链接

您可以在底部看到每页 15 条船。

'', 'section_intro' => '', 'posts_per_page' => '12', '订单' => '', 'price_from' => '', 'price_to' => '', '位置' => '', '功能' => '', '选项' => '', 'charter_lengths' => '', 'total_boat_capacity' => '', ), $atts ) ); $sc_att_order = $订单; $sc_att_posts_per_page = $posts_per_page; $sc_att_price_from = $price_from; $sc_att_price_to = $price_to; $sc_att_charter_lengths = $charter_lengths; $sc_att_locations = $位置; $sc_att_features = $特征; $sc_att_options = $选项; $sc_filtered_boat_capacity = $total_boat_capacity; if ( $sc_att_order == '最新' ) $sc_att_order = 'DESC'; elseif ( $sc_att_order == 'oldest' ) $sc_att_order = 'ASC'; 别的 $sc_att_order = 'DESC'; $paged = (get_query_var('paged')) ? get_query_var(“分页”):1; if( isset( $_GET['from'] ) && $_GET['from'] !== '') $filtered_price_from = (int)$_GET['from']; if( isset( $_GET['to'] ) && $_GET['to'] !== '') $filtered_price_to = (int)$_GET['to']; if(isset($_GET['boat_capacity']) && $_GET['boat_capacity'] !== '') $filtered_boat_capacity = (int)$_GET['boat_capacity']; if( isset( $_GET['buffet_dining_capacity'] ) && $_GET['buffet_dining_capacity'] !== '' ) $filtered_buffet_dining_capacity = (int)$_GET['buffet_dining_capacity']; if( isset( $_GET['cocktail_capacity'] ) && $_GET['cocktail_capacity'] !== '' ) $filtered_cocktail_capacity = (int)$_GET['cocktail_capacity']; if( isset( $_GET['formal_capacity'] ) && $_GET['formal_capacity'] !== '' ) $filtered_formal_dining_capacity = (int)$_GET['formal_capacity']; if( isset( $_GET['offshore_capacity'] ) && $_GET['offshore_capacity'] !== '' ) $filtered_offshore_capacity = (int)$_GET['offshore_capacity']; if( isset( $_GET['overnight_capacity'] ) && $_GET['overnight_capacity'] !== '' ) $filtered_overnight_capacity = (int)$_GET['overnight_capacity']; 如果(get_query_var('ycbe_locations')!=='任何') $filtered_locations = get_query_var('ycbe_locations'); 如果(get_query_var('ycbe_features')!=='任何') $filtered_features = get_query_var('ycbe_features'); 如果(get_query_var('ycbe_options')!=='任何') $filtered_options = get_query_var('ycbe_options'); 如果(get_query_var('ycbe_charter_lengths')!=='任何') $filtered_charter_lengths = get_query_var('ycbe_charter_lengths'); $meta_query = array('relation' => 'AND'); $tax_query = array('relation' => 'AND'); if( isset( $sc_att_price_from ) && $sc_att_price_from !== '' ) $meta_query[] = 数组( 'key' => '_ycbe_price_from', '价值' => $sc_att_price_from, '比较' => '>=', '类型' => '十进制', ); 别的 if( isset( $filtered_price_from ) ) $meta_query[] = 数组( 'key' => '_ycbe_price_from', '价值' => $filtered_price_from, '比较' => '>=', '类型' => '十进制', ); if( isset( $sc_att_price_to ) && $sc_att_price_to !== '' ) $meta_query[] = 数组( 'key' => '_ycbe_price_from', '价值' => $sc_att_price_to, '比较' => '>=', '类型' => '十进制', ); 别的 if( isset( $filtered_price_to ) ) $meta_query[] = 数组( 'key' => '_ycbe_price_from', '价值' => $filtered_price_to, '比较' => ' '十进制', ); 如果( isset( $sc_filtered_boat_capacity ) && $sc_filtered_boat_capacity != '' ) $meta_query[] = 数组( 'key' => '_ycbe_boat_capacity', '价值' => $sc_filtered_boat_capacity, '比较' => '>=', '类型' => '十进制', ); 如果(isset($filtered_buffet_dining_capacity)) $meta_query[] = 数组( 'key' => '_ycbe_buffet_dining_capacity', '价值' => $filtered_buffet_dining_capacity, '比较' => '>=', '类型' => '十进制', ); if( isset( $filtered_cocktail_capacity ) ) $meta_query[] = 数组( 'key' => '_ycbe_cocktail_capacity', '价值' => $filtered_cocktail_capacity, '比较' => '>=', '类型' => '十进制', ); 如果(isset($filtered_formal_dining_capacity)) $meta_query[] = 数组( 'key' => '_ycbe_formal_dining_capacity', '价值' => $filtered_formal_dining_capacity, '比较' => '>=', '类型' => '十进制', ); 如果(isset($filtered_offshore_capacity)) $meta_query[] = 数组( 'key' => '_ycbe_offshore_capacity', '价值' => $filtered_offshore_capacity, '比较' => '>=', '类型' => '十进制', ); if( isset( $filtered_overnight_capacity ) ) $meta_query[] = 数组( 'key' => '_ycbe_overnight_capacity', '价值' => $filtered_offshore_capacity, '比较' => '>=', '类型' => '十进制', ); if( isset( $sc_att_locations ) && $sc_att_locations !== '' ) $sc_att_locations = explode('+', $sc_att_locations); $tax_query_child = 数组(); foreach($sc_att_locations 作为 $sc_att_location) $tax_query_child[] = 数组( '分类' => 'ycbe_location', '字段' => '蛞蝓', '条款' => $sc_att_location, ); $tax_query[] = array_merge( ['relation'=>'OR'], $tax_query_child ); 别的 if( isset( $filtered_locations ) && $filtered_locations !== '' ) $filtered_locations = explode('+', $filtered_locations); $tax_query_child = 数组(); foreach( $filtered_locations 作为 $filtered_location ) $tax_query_child[] = 数组( '分类' => 'ycbe_location', '字段' => '蛞蝓', '条款' => $filtered_location, ); $tax_query[] = array_merge( ['relation'=>'OR'], $tax_query_child ); if( isset( $sc_att_features ) && $sc_att_features !== '' ) $sc_att_features = explode('+', $sc_att_features); foreach( $sc_att_features 作为 $sc_att_feature ) $tax_query[] = 数组( '分类' => 'ycbe_feature', '字段' => '蛞蝓', '条款' => $sc_att_feature, ); 别的 if( isset( $filtered_features ) && $filtered_features !== '' ) $filtered_features = explode('+', $filtered_features); foreach($filtered_features 作为 $filtered_feature) $tax_query[] = 数组( '分类' => 'ycbe_feature', '字段' => '蛞蝓', 'terms' => $filtered_feature, ); if( isset( $sc_att_options ) && $sc_att_options !== '' ) $sc_att_options = explode('+', $sc_att_options); foreach( $sc_att_options 作为 $sc_att_option ) $tax_query[] = 数组( '分类' => 'ycbe_option', '字段' => '蛞蝓', '条款' => $sc_att_option, ); 别的 if( isset( $filtered_options ) && $filtered_options !== '' ) $filtered_options = explode('+', $filtered_options); foreach( $filtered_options 作为 $filtered_option ) $tax_query[] = 数组( '分类' => 'ycbe_option', '字段' => '蛞蝓', 'terms' => $filtered_option, ); if( isset( $sc_att_charter_lengths ) && $sc_att_charter_lengths !== '' ) $sc_att_charter_lengths = explode('+', $sc_att_charter_lengths); $tax_query_child = 数组(); foreach($sc_att_charter_lengths 作为 $sc_att_charter_length) $tax_query_child[] = 数组( '关系' => '或', 大批 ( '分类' => 'ycbe_charter_length', '字段' => '蛞蝓', '条款' => $filtered_charter_length, ), ); $tax_query[] = array_merge( ['relation'=>'OR'], $tax_query_child ); 别的 if( isset( $filtered_charter_lengths ) && $filtered_charter_lengths !== '' ) $filtered_charter_lengths = explode('+', $filtered_charter_lengths); $tax_query_child = 数组(); foreach( $filtered_charter_lengths 作为 $filtered_charter_length ) $tax_query_child[] = 数组( '分类' => 'ycbe_charter_length', '字段' => '蛞蝓', '条款' => $filtered_charter_length, ); $tax_query[] = array_merge( ['relation'=>'OR'], $tax_query_child ); $post_query = 新的 WP_Query( 大批( 'post_type' => 'ycbe_boat', '订单' => $sc_att_order, 'posts_per_page' => $sc_att_posts_per_page, '分页' => $分页, 'meta_query' => $meta_query, 'tax_query' => $tax_query, ) ); 全球 $post; 全局 $wp_query; ob_start(); ?>
<div class="our-yachts-sections">
    <div class="yacht-charter-carousel-wrapper">
        <h3 class="center-title"><?php echo $section_title; ?></h3>
        <div class="title-block2"></div>
        <p class="yacht-intro-text"><?php echo $section_intro; ?></p>
        <div class="owl-carousel1 yacht-block-wrapper">
            <?php if( isset( $order ) ) 
                if ( $order == 'oldest' ) 
                    $yacht_order = 'ASC';
                 else 
                    $yacht_order = 'DESC';
                
            
            $args = array(
                'post_type' => 'ycbe_boat',
                'posts_per_page' => $posts_per_page,
                'order' => $yacht_order
            );

            //$post_query = new WP_Query( $args );
            if( $post_query->have_posts() ) 
                while( $post_query->have_posts() ) 
                    $post_query->the_post(); ?>
                    <div class="yacht-block">
                <?php if( has_post_thumbnail() )  ?>
                    <div class="yacht-block-image">
                        <?php $yacht_diff_days = yacht_diff_days( date( 'Y-m-d' ), get_the_time( 'Y-m-d' ) ); ?>
                        <?php if ( $yacht_diff_days < 20 )  ?>
                            <div class="new-icon"><?php _e( 'New', 'yachtcharter' ); ?></div>
                        <?php 
                        $src = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'medium' ); ?>
                        <a href="<?php echo the_permalink(); ?>"><img src="<?php echo $src[0]; ?>" /></a>
                    </div>
                <?php  ?>
                <div class="yacht-block-content">
                    <h3><a href="<?php echo the_permalink(); ?>"><?php the_title(); ?></a></h3>
                    <?php  echo '<p class="element-excerpt">' .  get_the_excerpt( get_the_ID()) . '</p>' ; ?>
                    <div class="title-block5"></div>
                    <?php
                    $main_feature_1 = get_post_meta( get_the_ID(), '_ycbe_boat_capacity', true );
                    $main_feature_2 = get_post_meta( get_the_ID(), '_ycbe_price_from', true );
                    $main_feature_3 = get_the_excerpt( get_the_ID());
                    if( $main_feature_1 || $main_feature_2 || $main_feature_3 )  ?>
                        <ul>
                            <?php

                            if( $main_feature_1 )  echo '<li>' . '<span class="element-capacity">' .'Total Capacity: <strong>' . get_post_meta( get_the_ID(), '_ycbe_boat_capacity', true ) . '</strong></span>' .'</li>'; 
                            if( $main_feature_2 )  echo '<li>' . '<span class="element-price-from">' .'Price P/H From: <strong>$'. get_post_meta( get_the_ID(), '_ycbe_price_from', true ) . '</strong></span>' . '</li>'; 

                            ?>
                        </ul>
                    <?php 
                    $boatAddress =  "/boats/" . get_the_title();
                    $boatAddress = str_replace(" ","-", $boatAddress); ?>
                    <a class="seeMoreButton" href="<?php echo the_permalink(); ?>">See More</a>
                </div>
            </div>
                <?php 
             ?>
        </div>
    </div>
</div>

<?php wp_reset_postdata();
return ob_get_clean();

add_shortcode('boat_carousel', 'ycbe_boat_carousel_shortcode'); ?>

我希望我已经按照应有的方式完成了所有工作。

非常感谢

丹尼·柯克

【问题讨论】:

发帖前请美化你的代码。我们无法理解您在这里的工作 您好,不知道该怎么做,我将代码从 ATOM 复制到上面的帖子中。当我尝试再次添加它时,它说代码很大。谢谢 这是所有可以下载的代码的链接。希望这是允许的,如果没有,好的做法道歉。 dropbox.com/s/xsxype37cvp9fjy/boat_carousel.php?dl=0 谢谢丹尼 【参考方案1】:

更改此行代码:

<img src="<?php echo $src[0]; ?>" />

到:

<img src="<?php echo $src[0]; ?>"  />

【讨论】:

以上是关于向轮播添加 Alt 标签的主要内容,如果未能解决你的问题,请参考以下文章

将Alt标签添加到轮播

使用JQuery实现图片轮播效果

用JQ去实现一个轮播效果

使用流畅的轮播在选项卡之间移动

如何用Bootstrap制作轮播图

JavaScript基础 -- 焦点图轮播(转载)