将Alt标签添加到轮播

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了将Alt标签添加到轮播相关的知识,希望对你有一定的参考价值。

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

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

不确定我是否应该将所有代码添加到此帖子中。

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

你可以看到底部的船只有15页。

'', 'section_intro' => '', 'posts_per_page' => '12', 'order' => '', 'price_from' => '', 'price_to' => '', 'locations' => '', 'features' => '', 'options' => '', 'charter_lengths' => '', 'total_boat_capacity' => '', ), $atts ) ); $sc_att_order = $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 = $locations; $sc_att_features = $features; $sc_att_options = $options; $sc_filtered_boat_capacity = $total_boat_capacity; if ( $sc_att_order == 'newest' ) { $sc_att_order = 'DESC'; } elseif ( $sc_att_order == 'oldest' ) { $sc_att_order = 'ASC'; } else { $sc_att_order = 'DESC'; } $paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 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']; } if( get_query_var( 'ycbe_locations' ) !== 'any' ) { $filtered_locations = get_query_var( 'ycbe_locations' ); } if( get_query_var( 'ycbe_features' ) !== 'any' ) { $filtered_features = get_query_var( 'ycbe_features' ); } if( get_query_var( 'ycbe_options' ) !== 'any' ) { $filtered_options = get_query_var( 'ycbe_options' ); } if( get_query_var( 'ycbe_charter_lengths' ) !== 'any' ) { $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[] = array( 'key' => '_ycbe_price_from', 'value' => $sc_att_price_from, 'compare' => '>=', 'type' => 'DECIMAL', ); } else { if( isset( $filtered_price_from ) ) { $meta_query[] = array( 'key' => '_ycbe_price_from', 'value' => $filtered_price_from, 'compare' => '>=', 'type' => 'DECIMAL', ); } } if( isset( $sc_att_price_to ) && $sc_att_price_to !== '' ) { $meta_query[] = array( 'key' => '_ycbe_price_from', 'value' => $sc_att_price_to, 'compare' => '>=', 'type' => 'DECIMAL', ); } else { if( isset( $filtered_price_to ) ) { $meta_query[] = array( 'key' => '_ycbe_price_from', 'value' => $filtered_price_to, 'compare' => ' 'DECIMAL', ); } } if( isset( $sc_filtered_boat_capacity ) && $sc_filtered_boat_capacity != '' ) { $meta_query[] = array( 'key' => '_ycbe_boat_capacity', 'value' => $sc_filtered_boat_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $filtered_buffet_dining_capacity ) ) { $meta_query[] = array( 'key' => '_ycbe_buffet_dining_capacity', 'value' => $filtered_buffet_dining_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $filtered_cocktail_capacity ) ) { $meta_query[] = array( 'key' => '_ycbe_cocktail_capacity', 'value' => $filtered_cocktail_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $filtered_formal_dining_capacity ) ) { $meta_query[] = array( 'key' => '_ycbe_formal_dining_capacity', 'value' => $filtered_formal_dining_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $filtered_offshore_capacity ) ) { $meta_query[] = array( 'key' => '_ycbe_offshore_capacity', 'value' => $filtered_offshore_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $filtered_overnight_capacity ) ) { $meta_query[] = array( 'key' => '_ycbe_overnight_capacity', 'value' => $filtered_offshore_capacity, 'compare' => '>=', 'type' => 'DECIMAL', ); } if( isset( $sc_att_locations ) && $sc_att_locations !== '' ) { $sc_att_locations = explode( '+', $sc_att_locations ); $tax_query_child = array(); foreach( $sc_att_locations as $sc_att_location ) { $tax_query_child[] = array( 'taxonomy' => 'ycbe_location', 'field' => 'slug', 'terms' => $sc_att_location, ); } $tax_query[] = array_merge( ['relation'=>'OR'], $tax_query_child ); } else { if( isset( $filtered_locations ) && $filtered_locations !== '' ) { $filtered_locations = explode( '+', $filtered_locations ); $tax_query_child = array(); foreach( $filtered_locations as $filtered_location ) { $tax_query_child[] = array( 'taxonomy' => 'ycbe_location', 'field' => 'slug', 'terms' => $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 as $sc_att_feature ) { $tax_query[] = array( 'taxonomy' => 'ycbe_feature', 'field' => 'slug', 'terms' => $sc_att_feature, ); } } else { if( isset( $filtered_features ) && $filtered_features !== '' ) { $filtered_features = explode( '+', $filtered_features ); foreach( $filtered_features as $filtered_feature ) { $tax_query[] = array( 'taxonomy' => 'ycbe_feature', 'field' => 'slug', 'terms' => $filtered_feature, ); } } } if( isset( $sc_att_options ) && $sc_att_options !== '' ) { $sc_att_options = explode( '+', $sc_att_options ); foreach( $sc_att_options as $sc_att_option ) { $tax_query[] = array( 'taxonomy' => 'ycbe_option', 'field' => 'slug', 'terms' => $sc_att_option, ); } } else { if( isset( $filtered_options ) && $filtered_options !== '' ) { $filtered_options = explode( '+', $filtered_options ); foreach( $filtered_options as $filtered_option ) { $tax_query[] = array( 'taxonomy' => 'ycbe_option', 'field' => 'slug', '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 = array(); foreach( $sc_att_charter_lengths as $sc_att_charter_length ) { $tax_query_child[] = array( 'relation' => 'OR', array ( 'taxonomy' => 'ycbe_charter_length', 'field' => 'slug', 'terms' => $filtered_charter_length, ), ); } $tax_query[] = array_merge( ['relation'=>'OR'], $tax_query_child ); } else { if( isset( $filtered_charter_lengths ) && $filtered_charter_lengths !== '' ) { $filtered_charter_lengths = explode( '+', $filtered_charter_lengths ); $tax_query_child = array(); foreach( $filtered_charter_lengths as $filtered_charter_length ) { $tax_query_child[] = array( 'taxonomy' => 'ycbe_charter_length', 'field' => 'slug', 'terms' => $filtered_charter_length, ); } $tax_query[] = array_merge( ['relation'=>'OR'], $tax_query_child ); } } $post_query = new WP_Query( array( 'post_type' => 'ycbe_boat', 'order' => $sc_att_order, 'posts_per_page' => $sc_att_posts_per_page, 'paged' => $paged, 'meta_query' => $meta_query, 'tax_query' => $tax_query, ) ); global $post; global $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'); ?>

我希望我已经完成了应有的一切。

非常感谢

丹尼柯克

答案

更改此行代码:

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

至:

<img src="<?php echo $src[0]; ?>" alt="<?php echo get_post_meta(get_post_thumbnail_id( $post->ID ), '_wp_attachment_image_alt', true); ?>" />

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

当我提出新请求时,Ajax http 请求将以前的图像加载到轮播中

图像未加载到轮播中

从引导网格列到轮播

如何在sencha touch中将图像从商店动态绑定到轮播

javascript基础01

重复提交搜索表单时添加和删除owl轮播项目