Skip to content

Instantly share code, notes, and snippets.

@vbaimas
Last active July 1, 2018 23:40
Show Gist options
  • Save vbaimas/b01b1b2b5b3da096d7b711ba62036b22 to your computer and use it in GitHub Desktop.
Save vbaimas/b01b1b2b5b3da096d7b711ba62036b22 to your computer and use it in GitHub Desktop.
Testimonials Carousel in WordPress using Custom Post Types, Advanced Custom Fields and Slick Carousel jQuery.
<?php
// Register Custom Post Type
function quote() {
$labels = array(
'name' => _x( 'quote', 'Post Type General Name', 'quote' ),
'singular_name' => _x( 'quote', 'Post Type Singular Name', 'quote' ),
'menu_name' => __( 'Quote', 'quote' ),
'name_admin_bar' => __( 'Quote', 'quote' ),
'archives' => __( 'Item Archives', 'quote' ),
'attributes' => __( 'Item Attributes', 'quote' ),
'parent_item_colon' => __( 'Parent Item:', 'quote' ),
'all_items' => __( 'All Quotes', 'quote' ),
'add_new_item' => __( 'Add New Quote', 'quote' ),
'add_new' => __( 'Add New quote', 'quote' ),
'new_item' => __( 'New Item quote', 'quote' ),
'edit_item' => __( 'Edit quote', 'quote' ),
'update_item' => __( 'Update quote', 'quote' ),
'view_item' => __( 'View Item quote', 'quote' ),
'view_items' => __( 'View Items of quotes', 'quote' ),
'search_items' => __( 'Search Item quote', 'quote' ),
'not_found' => __( 'Quote Not found', 'quote' ),
'not_found_in_trash' => __( 'Quote Not found in Trash', 'quote' ),
'featured_image' => __( 'Quote Featured Image', 'quote' ),
'set_featured_image' => __( 'Set featured image of quote', 'quote' ),
'remove_featured_image' => __( 'Remove featured image of quote', 'quote' ),
'use_featured_image' => __( 'Use as featured image for quote', 'quote' ),
'insert_into_item' => __( 'Insert into item', 'quote' ),
'uploaded_to_this_item' => __( 'Uploaded to this item', 'quote' ),
'items_list' => __( 'Items list', 'quote' ),
'items_list_navigation' => __( 'Items list navigation', 'quote' ),
'filter_items_list' => __( 'Filter items list', 'quote' ),
);
$args = array(
'label' => __( 'quote', 'quote' ),
'description' => __( 'Post Type Description', 'quote' ),
'labels' => $labels,
'supports' => array( 'title', 'custom-fields', ),
'menu_icon' => 'dashicons-editor-quote',
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'quote', $args );
}
add_action( 'init', 'quote', 0 );
//* Enqueue Slick's CSS and Javascript
// load from js and CSS folders
add_action( 'wp_enqueue_scripts', 'enqueue_slick' );
function enqueue_slick() {
wp_enqueue_script ('jQuery.vbaimas', get_template_directory_uri() . '/js/jQuery.vbaimas.js', array('jquery'));
wp_enqueue_script( 'slick.min', get_template_directory_uri() . 'js/slick.min.js', 'jquery', 1.0 );
wp_enqueue_style('slick-theme', get_template_directory_uri() . '/css/slick-theme.css');
wp_enqueue_style( 'slick-styles', get_template_directory_uri() . '/css/slick.css' );
}
<section class="quotes">
<div class="quotes-content">
<div class="row">
<h2>Testimonials from <span class="w700">our clients</span></h2>
</div>
<div class="row">
<div class="lg-6 lg-offset-3 columns">
<?php
$args = array(
'post_type' => 'quote',
'posts_per_page' =>4,
'orderby' => 'ASC',
'post_status' => 'publish',
);
?>
<span class="quote-open"></span>
<div class="quotes-slider">
<?php $quote = new WP_Query( $args );?>
<?php if ($quote->have_posts()) :?>
<?php while ($quote->have_posts()) : $quote->the_post(); ?>
<p><?php the_field('quote_text'); ?></p>
<h3>&mdash; <?php the_field('quote_name'); ?></h3>
<p class="quote_company"><?php the_field('quote_company')?></p>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>
<?php else: ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
</div>
</div>
</div>
</div>
</section>
jQuery(document).ready(function($) {
$('.quotes-slider').slick({
dots: true,
infinite: true,
autoplay: true,
autoplaySpeed: 8000,
slidesToShow: 1,
slidesToScroll: 1,
adaptiveHeight: true,
draggable:true,
fade:true,
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment