slick slider as custom post type

First of all you’ve written array(jquery) instead of array('jquery'). And also has not defined the slickinit enqueue position. So the right code will be-

 //Enqueue scripts
add_action('wp_enqueue_scripts', 'wp_enqueue_all_scripts', 999);

function wp_enqueue_all_scripts(){

    //add slick slider
    wp_register_style('slickcss', get_template_directory_uri() . '/slick/slick.css' );
    wp_register_style('slickcsstheme', get_template_directory_uri() . '/slick/slick-theme.css' );

    //load slick js
    wp_register_script('slickslider', get_template_directory_uri() . '/slick/slick.min.js', array('jquery'), '', true );

    ////load slick initiate script
    wp_register_script( 'slickinit', get_template_directory_uri() . '/assets/js/slick-init.js',  array( 'jquery', 'slickslider' ) );

    // load slick on homepage
    if ( is_front_page() ) {
        wp_enqueue_style( 'slickcss' );
        wp_enqueue_style( 'slickcsstheme' );
        wp_enqueue_script ('slickslider');
        wp_enqueue_script ('slickinit');
    }
}

And at your front-page.php try this-

<?php get_header(); ?>

<?php

// WP_Query arguments
$args = array (
    'post_type'              => array( 'slider' ),
);

// The Query
$query_slider = new WP_Query( $args );

// The Loop
if ( $query_slider->have_posts() ) {
    echo '<div class="home regular slider">';
    while ( $query_slider->have_posts() ) {
        $query_slider->the_post();
        echo '<div class="featured-image-slider"> ';
        the_post_thumbnail();
        echo '</div>';
    }
    echo '</div>';
} else {
    // no posts found
}

// Restore original Post Data
wp_reset_postdata();

?>

<?php  get_footer(); ?>

Hope that thing will be working now.

Leave a Comment