【发布时间】:2018-01-15 05:58:12
【问题描述】:
我正在尝试使用光滑的滑块作为 WordPress 单个 CPT 页面上的“上一个”和“下一个”按钮。
因此,滑块将调用特定 CPT 的所有帖子并显示当前帖子的特色图片,并且在任一侧它都会显示上一个和下一个帖子的特色图片。
当您浏览幻灯片时,会出现相应的内容。
问题在于,当您滑过时,您将获得正确的图像和内容,但 URL 保持不变。此外,您不能链接到特定帖子,因为它只会转到幻灯片的开头。
现在,这就是我的single-CPT.php 的样子
<?php
get_header();
rewind_posts();
if (have_posts()) {
while ( have_posts() ) : the_post();
$post_id = get_the_ID();
?>
// BEGIN SLIDER (WHERE FEATURED IMAGES ARE THE SLIDES)//
<section class="slider center">
<?php
$index = 0;
$carousel_args = array(
'post_type' => 'CPT',
'posts_per_page' => -1,
);
$carousel_query = new WP_Query( $carousel_args );
if ( $carousel_query->have_posts() ) {
while ( $carousel_query->have_posts() ) {
$carousel_query->the_post();
$title = get_the_title();
$link = get_permalink();
if ( has_post_thumbnail() ) {
$post_thumbnail_id = get_post_thumbnail_id();
$post_thumbnail_image = wp_get_attachment_image_src( $post_thumbnail_id, 'large' );
$post_thumb = $post_thumbnail_image[0];
} else {
$post_thumb = '';
}
$content = get_the_content();
$excerpt = get_the_excerpt();
// output//
?>
<div class="wow slide-in slide">
<div class="active">
<a href="<?php echo $link; ?>">
<img src="<?php echo $post_thumb; ?>" />
</a>
</div>
</div>
<?php $index++;
}
}
wp_reset_postdata();
endwhile;
?>
</section>
//END SLIDER - BEGIN CONTENT//
<div id="archive-post">
<div class="row">
<div class="columns small-12 medium-10 medium-offset-1 large-offset-0 large-8">
<article id="post-<?php the_ID(); ?>" role="article">
<div class="post-title">
<div class="row">
<div class="columns">
<h3><?php the_title(); ?></h3>
</div>
</div>
</div>
<div class="post-content">
<div class="row">
<div class="columns">
<?php the_content(); ?>
</div>
</div>
</div>
</article>
</div>
</div>
</div>
基本上,我需要在不刷新页面的情况下将 URL 与幻灯片一起更新。有没有办法做到这一点?
【问题讨论】:
标签: javascript wordpress slick.js