Добавление Alt-тегов в карусель - PullRequest
0 голосов
/ 03 декабря 2018

Я пытаюсь добавить 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' => '', 'location'=> '', '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 = $ location;$ 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 == 'old') {$ 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']! == '') {$ Filter_price_from = (int) $ _ GET ['from'];} if (isset ($ _GET ['to']) && $ _GET ['to']! == '') {$ Filter_price_to = (int) $ _ GET ['to'];} if (isset ($ _GET ['boat_capacity']) && $ _GET ['boat_capacity']! == '') {$ Filter_boat_capacity = (int) $ _ GET ['boat_capacity'];} if (isset ($ _GET ['buff_dining_capacity']) && $ _GET ['шведский стол_dining_capacity']! == '' {$ Filter_buffet_dining_capacity = (int) $ _ GET ['buff_dining_capacity'];} if (isset ($ _GET ['cocktail_capacity']) && $ _GET ['коктейль_capacity']! == '') {$ Filter_cocktail_capacity = (int) $ _ GET ['коктейль_capacity'];} if (isset ($ _GET ['formal_capacity']) && $ _GET ['formal_capacity']! == '') {$ Filter_formal_dining_capacity = (int) $ _ GET ['formal_capacity'];} if (isset ($ _GET ['offshore_capacity']) && $ _GET ['offshore_capacity']! == '') {$ Filter_offshore_capacity = (int) $ _ GET ['offshore_capacity'];} if (isset ($ _GET ['overnight_capacity']) && $ _GET ['overnight_capacity']! == '') {$ Filter_overnight_capacity = (int) $ _ GET ['overnight_capacity'];} if (get_query_var ('ycbe_locations')! == 'any') {$ Filter_locations = get_query_var ('ycbe_locations');} if (get_query_var ('ycbe_features')! == 'any') {$ Filter_features = get_query_var ('ycbe_features');} if (get_query_var ('ycbe_options')! == 'any') {$ Filter_options = get_query_var ('ycbe_options');} if (get_query_var ('ycbe_charter_lengths')! == 'any') {$ Filter_charter_lengths = get_query_var ('ycbe_charter_lengths');} $ meta_query = array ('ratio' => 'AND');$ tax_query = array ('ratio' => 'AND');if (isset ($ sc_att_price_from) && $ sc_att_price_from! == '') {$ meta_query [] = массив ('key' => '_ycbe_price_from', 'value' => $ sc_att_price_from, 'Compare' => '> =' ', 'type' => 'DECIMAL',);} else {if (isset ($ Filter_price_from)) {$ meta_query [] = массив ('key' => '_ycbe_price_from', 'value' => $ Filter_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 ($ Filter_price_to)) {$ meta_query [] = массив ('key' => '_ycbe_price_from', 'value' => $ Filter_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 ($ Filter_buffet_dining_capacity)) {$ meta_query [] = array ('key' => '_ycbe_buffet_dining_capacity', 'value' => $ Filter_buffet_dining_capacity, 'Compare' => '> =', 'type' => 'ДЕСЯТИЧНЫЙ', );} if (isset ($ Filter_cocktail_capacity)) {$ meta_query [] = array ('key' => '_ycbe_cocktail_capacity', 'value' => $ Filter_cocktail_capacity, 'сравнить' => '> =', 'type' => 'ДЕСЯТИЧНЫЙ', );} if (isset ($ Filter_formal_dining_capacity)) {$ meta_query [] = array ('key' => '_ycbe_formal_dining_capacity', 'value' => $ Filter_formal_dining_capacity, 'Compare' => '> =', 'type' => 'ДЕСЯТИЧНЫЙ', );} if (isset ($ Filter_offshore_capacity)) {$ meta_query [] = массив ('key' => '_ycbe_offshore_capacity', 'value' => $ Filter_offshore_capacity, 'сравнить' => '> =', 'type' => 'ДЕСЯТИЧНЫЙ', );} if (isset ($ Filter_overnight_capacity)) {$ meta_query [] = array ('key' => '_ycbe_overnight_capacity', 'value' => $ Filter_offshore_capacity, 'сравнить' => '> =', 'type' => 'ДЕСЯТИЧНЫЙ', );} 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', 'rules' => $ sc_att_location,);} $ tax_query [] = array_merge (['ratio' => 'OR'], $ tax_query_child);} else {if (isset ($ Filter_locations) && $ Filter_locations! == '') {$ Filter_locations = Explode ('+', $ Filter_locations);$ tax_query_child = array ();foreach ($ Filter_Locations как $ Filter_Location) {$ tax_query_child [] = array ('taxonomy' => 'ycbe_location', 'field' => 'slug', 'rules' => $ Filter_location,);} $ tax_query [] = array_merge (['ratio' => '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', 'rules' => $ sc_att_feature,);}} else {if (isset ($ Filter_features) && $ Filter_features! == '') {$ Filter_features = Explode ('+', $ Filter_features);foreach ($ Filter_features as $ Filter_feature) {$ tax_query [] = массив ('taxonomy' => 'ycbe_feature', 'field' => 'slug', 'rules' => $ Filter_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 [] = массив ('taxonomy' => 'ycbe_option', 'field' => 'slug', 'rules' => $ sc_att_option,);}} else {if (isset ($ Filter_options) && $ Filter_options! == '') {$ Filter_options = Explode ('+', $ Filter_options);foreach ($ Filter_options as $ Filter_option) {$ tax_query [] = массив ('taxonomy' => 'ycbe_option', 'field' => 'slug', 'rules' => $ Filter_option,);}}} if (isset ($ sc_att_charter_lengths) && $ sc_att_charter_lengths! == '') {$ sc_att_charter_lengths = взорваться ('+', $ sc_att_charter_lengths);$ tax_query_child = array ();foreach ($ sc_att_charter_lengths as $ sc_att_charter_length) {$ tax_query_child [] = массив ('отношение' => 'ИЛИ', массив ('таксономия' => 'ycbe_charter_length', 'field' => 'slug', 'rules' =>$ Filter_charter_length,),);} $ tax_query [] = array_merge (['ratio' => 'OR'], $ tax_query_child);} else {if (isset ($ Filter_charter_lengths) && $ Filter_charter_lengths! == '') {$ Filter_charter_lengths = Explode ('+', $ Filter_charter_lengths);$ tax_query_child = array ();foreach ($ filter_charter_lengths как $ Filter_charter_length) {$ tax_query_child [] = array ('taxonomy' => 'ycbe_charter_length', 'field' => 'slug', 'rules' => $ Filter_charter_length,);} $ tax_query [] = array_merge (['ratio' => 'OR'], $ tax_query_child);}} $ post_query = new WP_Query (массив ('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,));глобальный $ 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');?>

Надеюсь, я сделал все так, как должно быть.

Большое спасибо

Дэнни Кирк

1 Ответ

0 голосов
/ 29 апреля 2019

Измените код этой строки:

<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); ?>" />
...