我正在尝试创建一个滑块,用于显示包含自定义帖子类型帖子(推荐)信息的幻灯片。我设置了一个页面模板,可以用帖子内容生成div,但是处理slider元素的最佳方法是什么?
P、 如果可能的话,我希望幻灯片也以随机顺序显示。
以下是我的页面模板的代码:
<?php
/**
* Template Name: Testimonials Page
*/
get_header(); ?>
<div id="primary" class="content-area">
<main id="main" class="site-main" role="main">
<?php
while ( have_posts() ) : the_post();
get_template_part( \'template-parts/content\', \'page\' );
// If comments are open or we have at least one comment, load up the comment template.
if ( comments_open() || get_comments_number() ) :
comments_template();
endif;
endwhile; // End of the loop.
?>
</main><!-- #main -->
</div><!-- #primary -->
<div class="home-page-testimonials">
<h1>Don\'t just take our word for it...</h1>
<?php
$args = array( \'post_type\' => \'testimonials\' );
$the_query = new WP_Query( $args );
$thumbnailURL;
?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<div class="home-page-testimonial">
<img class="home-page-testimonial-icon" src="<?php if ( has_post_thumbnail() ) {
$thumbnailURL = the_post_thumbnail_url( array(120,120) );
} else {
$thumbnailURL = get_stylesheet_directory_uri() . "/images/DefaultTestimonialIcon.png";
}
echo $thumbnailURL; ?>">
<div class="home-page-testimonial-info">
<div class="entry-content">
<h2><?php the_title(); ?></h2>
<?php if ( ! empty( get_post_meta($post->ID, "_testimonialURL", true) ) ) {
echo \'<p class="home-page-testimonial-link"><a href="\' . get_post_meta($post->ID, "_testimonialURL", true) . \'" target="_blank">\' . get_post_meta($post->ID, "_testimonialWebsiteName", true) . \'</a></p>\';
} ?>
<div class="home-page-testimonial-quote"><?php the_content(); ?></div>
</div>
</div>
</div>
<?php wp_reset_postdata(); endwhile; endif;
?>
</div>