因此, 我用Bootstrap制作了一个轮播, 并将其粘贴到我的wordpress主题中。我已经尝试将其与一些WP代码结合起来, 希望你们能对我有所帮助。
<div class="carousel-inner text-uppercase font-weight-bold">
<?php $the_query = new WP_Query( 'posts_per_page=4' ); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="carousel-item active">
<a href="<?php the_permalink() ?>"><img src="<?php the_post_thumbnail_url('wide');?>" class="d-block w-100">
<h2 class="carousel-caption bg-black w-auto font-weight-bold font-italic">
<?php the_title(); ?>
</h2>
</a>
</div>
<?php endwhile; wp_reset_postdata();?>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
#1
确保你包含jQuery, 检查控制台是否有错误。
#2
我知道了
<div id="carouselExampleIndicators" class="carousel slide pt-4" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="3"></li>
</ol>
<div class="carousel-inner text-uppercase font-weight-bold">
<?php $the_query = new WP_Query(array('posts_per_page'=>1, 'tag'=>'favorite')); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="carousel-item active">
<a href="<?php the_permalink() ?>"><img src="<?php the_post_thumbnail_url('wide');?>" class="d-block w-100">
<h2 class="carousel-caption bg-black w-auto font-weight-bold font-italic">
<?php the_title(); ?>
</h2>
</a>
</div>
<?php endwhile; wp_reset_postdata();?>
<?php $the_query = new WP_Query(array('posts_per_page'=>3, 'tag'=>'favorite', 'offset'=>1)); ?>
<?php while ($the_query -> have_posts()) : $the_query -> the_post(); ?>
<div class="carousel-item">
<a href="<?php the_permalink() ?>"><img src="<?php the_post_thumbnail_url('wide');?>" class="d-block w-100">
<h2 class="carousel-caption bg-black w-auto font-weight-bold font-italic">
<?php the_title(); ?>
</h2>
</a>
</div>
<?php endwhile; wp_reset_postdata();?>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
评论前必须登录!
注册