证明滑块循环/查询不起作用PHP Wordpress



所以,我试图用Slick滑块显示Testimonials,但它不起作用。我想我把css和js文件链接错了,或者是因为正在显示推荐信,但滑块不起作用。因此,请帮助进行故障排除。

这是代码:

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_enque_scripts','load_css'(;

函数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_enque_scripts','load_js'(;

用JQUERY调用它//这只是一行代码,它应该可以在中工作

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

是否在document.ready状态上附加.slick((回调?

最后,我用带数字字段的高级自定义字段实现了这一点。我放弃了滑球,稍微改变了一下概念。因此,根据字段中输入的数字,它将在前端生成恒星的数量。

<?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(); ?>

最新更新