Wordpress owl carousel add empty item

别来无恙 提交于 2021-02-08 06:14:28

问题


I've got a question with pre-install widget in my theme (called meteroite). The full widget code if needed is here: https://codeshare.io/5Mbrne

This is the exact part responsible for displaying all of my CPT 'employees' items:

$employees = new WP_Query(array(
            'no_found_rows'     => true,
            'post_status'       => 'publish',
            'post_type'         => 'employees',
            'posts_per_page'    => $number,
            'employee-category' => $category
        ) );

        $type_class = '';
        if ( $type == 'Square' ) :
            $type_class = 'square';
        elseif ( $type == 'Round' ) :
            $type_class = 'round';
        endif;

        $data_autoplay = 'false';
        if ( $enable_autoplay == 'On' ) :
            $data_autoplay = intval($autoplay);
        endif;

        $data_pagination = 'false';
        if ( $pagination == 'Show' ) :
            $data_pagination = 'true';
        endif;

        $centered_class = '';
        if ( $center_content == 'Yes' ) :
            $centered_class = 'centered';
        endif;

        $animation_class = '';
        $animation_single = '';
        if ( $animation == 'Fade In' ) {
            $animation_class = 'fade-in';
        } elseif ( $animation == 'Fade In Up' ) {
            $animation_class = 'fade-in-up';
        } elseif ( $animation == 'Fade In Left' ) {
            $animation_class = 'fade-in-left';
        } elseif ( $animation == 'Fade In Right' ) {
            $animation_class = 'fade-in-right';
        } elseif ( $animation == 'Fade In One By One' ) {
            $animation_single = 'fade-in-single';
        } elseif ( $animation == 'Fade In Up One By One' ) {
            $animation_single = 'fade-in-up-single';
        }

        echo $args['before_widget'];

        if ( $title ) { echo $args['before_title'] . $title . $args['after_title']; }

        if ( $employees->have_posts() && post_type_exists( 'employees' )  ) : ?>

        <div class="meteorite-team carousel owl-carousel <?php echo $centered_class . ' ' . $animation_class . $animation_single; ?>" data-items-large="<?php echo $itemsLarge; ?>" data-items-medium="<?php echo $itemsMedium; ?>" data-items-small="<?php echo $itemsSmall; ?>" data-autoplay="<?php echo $data_autoplay; ?>" data-pagination="<?php echo $data_pagination; ?>">
            <?php while ( $employees->have_posts() ) : $employees->the_post(); ?>
                <?php //Get the custom field values
                    $position       = get_post_meta( get_the_ID(), 'tt-position', true );
                    $socialOne      = get_post_meta( get_the_ID(), 'tt-socialOne', true );
                    $socialTwo      = get_post_meta( get_the_ID(), 'tt-socialTwo', true );
                    $socialThree    = get_post_meta( get_the_ID(), 'tt-socialThree', true );
                    $empMail        = get_post_meta( get_the_ID(), 'tt-mail', true );
                    $link           = get_post_meta( get_the_ID(), 'tt-custom-link', true );
                ?>
                <div class="team-item meteorite-item <?php echo $type_class; ?>">
                    <div class="team-inner">
                        <?php if ( has_post_thumbnail() ) : ?>
                        <div class="avatar">
                            <?php the_post_thumbnail(); ?>
                        </div>
                        <?php endif; ?>
                        <div class="team-content">
                            <div class="name">
                                <?php if ( $link == '' ) : ?>
                                    <?php the_title(); ?>
                                <?php else : ?>
                                    <a href="<?php echo esc_url( $link ); ?>"><?php the_title(); ?></a>
                                <?php endif; ?>
                            </div>
                            <div class="pos"><?php echo esc_html( $position ); ?></div>
                            <div class="excerpt">
                                <?php the_content(); ?>
                            </div>
                        </div>
                        <div class="team-social">
                            <ul class="team-social social-icons">
                                <?php if ( $socialOne != '' ) : ?>
                                    <li><a href="<?php echo esc_url( $socialOne ); ?>" target="_blank"></a></li>
                                <?php endif; ?>
                                <?php if ( $socialTwo != '' ) : ?>
                                    <li><a href="<?php echo esc_url( $socialTwo ); ?>" target="_blank"></a></li>
                                <?php endif; ?>
                                <?php if ( $socialThree != '' ) : ?>
                                    <li><a href="<?php echo esc_url( $socialThree ); ?>" target="_blank"></a></li>
                                <?php endif; ?>
                                <?php if ( $empMail != '' ) : ?>
                                    <li><a href="mailto:<?php echo sanitize_email( $empMail ); ?>"></a></li>
                                <?php endif; ?>
                            </ul>
                        </div>
                    </div>
                </div>
            <?php endwhile; ?>
        </div>

        <?php
        wp_reset_postdata(); ?>

Issue description: I've got 3 items inside the CPT (lets call them: Joe / Harry / Adam). Nothing else, only three posts. But while displaying, owl carousel (so the script responsible for the carousel) generates 4 items, which from the last one -> is empty. SO its extremely consufing for my page viewers when they are swaping/scrolling the items and the last is blank. Do you have any idea what is that?

来源:https://stackoverflow.com/questions/47483893/wordpress-owl-carousel-add-empty-item

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!