skip to Main Content

So, I am trying to display Testimonials with Slick slider but it is not working. I guess I linked the css and js files wrong or something because testimonials are displaying but slider doesn’t work. So please help with troubleshooting.

This is code:

HTML

    <section class="reviews">
                <div class="row d-flex flex-column">
                    <div class="testimonial-holder">                
                        <?php
                            $args = array(
                            'post_type'   => 'testimonials',
                            // 'post_status' => 'publish',
                            // 'posts_per_page' => 1,
                            // 'order' => 'ASC',
                            );
                            $query = new WP_Query( $args );
                        ?>
                            <?php
                            while( $query->have_posts() ) :
                                $query->the_post(); 
                        ?>

                            <div class="lead-text d-flex text-center justify-content-center flex-column">
                                <?php echo '<p class="lead">' . get_the_content() . '</p>' . '<small>' . '-' . get_the_title() . '</small>'; ?>
                            </div>
                        <?php endwhile;
                        wp_reset_postdata(); ?>
                    </div>
                </div>
            </section>

ENQUE

function load_css() {

wp_register_style( 'slick', get_template_directory_uri() . '/src/js/slick/slick.css', array(), false, 'all' );
wp_enqueue_style('slick');

}
add_action( ‘wp_enqueue_scripts’, ‘load_css’ );

function load_js() {

wp_register_script( 'slick', get_template_directory_uri() . '/src/js/slick/slick.min.js', false, true);
wp_enqueue_script('slick');

}
add_action( ‘wp_enqueue_scripts’, ‘load_js’ );

CALLING IT WITH JQUERY//This is only line of code and it should work

$('.testimonial-holder').slick();

2

Answers


  1. Chosen as BEST ANSWER

    At the end I pulled this off with Advanced Custom Fields with number field. I gave up on slider and changed the concept little bit. So, depends of the entered number in the filed, it will generate number of stars in the Front end.

    <?php
                                $args = array(
                                'post_type'   => 'testimonials',
                                'post_status' => 'publish',
                                'posts_per_page' => 1,
                                'order' => 'DESC',
                                'orderby'=> 'rand',
                                );
                                $query = new WP_Query( $args );
                                    //if( $query->have_posts() ) :
                            ?>
                                <!-- Displaying testimonials -->
                        
                            <?php
                                while( $query->have_posts() ) : ?>
                                    <!-- <div class="col-lg-4"> -->
                                    <div class="content-holder">
                                        <?php $query->the_post(); ?>
    
                                        <div class="stars-holder">
                                            <?php 
                                                $star = get_field('stars');
                                                $count = 0;
                                                $element = '<i class="fa fa-star"></i>';
                                                while ($count < $star) : $count++;
                                                    echo $element;
                                                endwhile;
                                            ?>  
                                        </div>                  
                                        <div class="lead-text d-flex text-center justify-content-center flex-column">
                                            <?php echo '<p class="lead">' . get_the_content() . '</p>' . '<small>' . '-' . get_the_title() . '</small>'; ?>
                                        </div>
                                    </div>
                                <!-- </div> -->
                                <?php endwhile;
                                wp_reset_postdata(); ?>
    

  2. Did you attach the .slick() callback on document.ready state?

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search