我想将Wordpress帖子项目显示为滑块,但它们似乎正在堆叠并且没有从左到右滑动,因此轮播控件无法正常工作。如果我将'posts_per_page'=> 1,则第二条帖子消失,但是如果我将'posts_per_page'=> 10,则它们堆叠。任何帮助将不胜感激。 非常感谢, 卡利
$post = get_field('post');
?>
<!-- OPEN CAROUSEL LOOP -->
<?php
$loop = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 1,
'orderyby' => 'post_id',
'order' => 'ASC',
)); ?>
<?php
while ( $loop->have_posts() ) : $loop->the_post();
?>
<!-- START CAROUSEL **************************************************************** -->
<div id="news-carousel" class="carousel slide" data-ride="carousel">
<!-- **************************************************************** -->
<!-- Indicators -->
<ul class="carousel-indicators">
<?php
$active = 'active';
$num = 0;
?>
<li data-target="#carousel1" data-slide-to="<?php echo $num ?>" class="<?php echo $active ?>"></li>
<?php
$active = '';
$num += 1;
?>
</ul>
<!-- **************************************************************** -->
<?php if ( has_post_thumbnail() ) { ?>
<!-- The slideshow -->
<div class="carousel-inner" role="listbox" >
<?php $active = 'active'; ?>
<div class="carousel-item <?php echo $active ?>">
<div >
<?php the_post_thumbnail( 'full' ); ?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</div>
</div><!-- /item -->
<?php $active = ''; ?>
</div>
<!-- // End The slideshow -->
<?php } ?>
<!-- **************************************************************** -->
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#news-carousel" role="button" data-slide="prev">
<i class="fa fa-chevron-left"></i> </a>
<a class="carousel-control-next" href="#news-carousel" role="button" data-slide="next">
<i style="color: black;" class="fa fa-chevron-right"></i> </a>
</div> <!-- Carousel 1 -->
<!-- End Carousel **************************************************************** -->
<?php
endwhile;
wp_reset_postdata();
?>
答案 0 :(得分:0)
Try to use this code:
<!--OPEN CAROUSEL LOOP-->
<?php $loop = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 6,
'orderyby' => 'post_id',
'order' => 'ASC' ));
?>
<!--CAROUSEL indicators SECTION START HERE-->
<ul class="carousel-indicators">
<?php $count = 0; while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li data-target="#carousel1" data-slide-to="<?php echo $count ?>" class="<?php if($count == '0'){ echo 'active'; } ?>"></li>
<?php $count++; endwhile; wp_reset_postdata(); ?>
</ul>
<!--//CAROUSEL indicators SECTION END HERE-->
<!--CAROUSEL SLIDER SECTION START HERE-->
<div id="news-carousel" class="carousel slide" data-ride="carousel">
<?php $count = 0; while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<!-- The slideshow -->
<div class="carousel-inner" role="listbox" >
<div class="carousel-item <?php if($count == '0'){ echo 'active'; } ?>">
<div >
<?php the_post_thumbnail( 'full' ); ?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</div>
</div><!-- /item -->
</div>
<!-- // End The slideshow -->
<?php } ?>
<!-- **************************************************************** -->
<?php $count++; endwhile; wp_reset_postdata(); ?>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#news-carousel" role="button" data-slide="prev">
<i class="fa fa-chevron-left"></i> </a>
<a class="carousel-control-next" href="#news-carousel" role="button" data-slide="next">
<i style="color: black;" class="fa fa-chevron-right"></i> </a>
</div> <!-- Carousel 1 -->
<!--//CAROUSEL SLIDER SECTION END HERE-->
<!--//CAROUSEL indicators SECTION End HERE-->
答案 1 :(得分:0)
Shammi,感谢您的上述帮助,我重新编写了代码,并设法使其正常工作。这是:
$carousel_item = get_field('carousel_item');
?>
<!--OPEN CAROUSEL LOOP-->
<?php $loop = new WP_Query(array(
'post_type' => 'post',
'posts_per_page' => 6,
'orderyby' => 'post_id',
'order' => 'ASC' ));
?>
<div id="demo" class="carousel slide" data-ride="carousel">
<!-- Indicators -->
<ul class="carousel-indicators">
<?php $count = 0; while ( $loop->have_posts() ) : $loop->the_post(); ?>
<li data-target="#news-carousel" data-slide-to="<?php echo $count ?>" class="<?php if($count == '0'){ echo 'active'; } ?>"></li>
<?php $count++; endwhile; wp_reset_postdata(); ?>
</ul>
<?php $count = 0; while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php if ( has_post_thumbnail() ) { ?>
<!-- The slideshow -->
<div class="carousel-item <?php if($count == '0'){ echo 'active'; } ?>">
<div >
<?php the_post_thumbnail( 'full' ); ?>
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
</div>
</div><!-- /item -->
<?php } ?>
<?php $count++; endwhile; wp_reset_postdata(); ?>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#demo" role="button" data-slide="prev">
<i class="fa fa-chevron-left"></i> </a>
<a class="carousel-control-next" href="#demo" role="button" data-slide="next">
<i style="color: black;" class="fa fa-chevron-right"></i> </a>
</div> <!-- Carousel 1 -->