php - 如何将当前的 Bootstrap 卡片视图显示更改为 Bootstrap Carousel?
问题描述
下面是我的代码,帖子在卡片上显示得很好,但我尝试了很多次将其更改为轮播,但没有奏效。
我想使用下面链接中的相同轮播。
轮播参考:https ://gosnippets.com/snippets/bootstrap-carousel-with-cards-in-3-columns
<?php
//var_dump($get_packages_list);
if($get_packages_list){
foreach($get_packages_list as $get_package){?>
<div class="row">
<div class="col-md-12">
<div class="packages_list_body">
<div class="packages_cards_inner_wrap" id="package-<?php echo $get_package->post_name;?>">
<h2 id="bundle_p_title" style="color:#a52a2a; margin-left: 12px;"><?php echo $get_package->post_title.' - <small>'.$default_plan_title.'</small>';?></h2>
<div class="packages_cards row">
<?php
$podcasts = get_field('podcasts', $get_package->ID);
$minimum_price = get_field('minimum_price', $get_package->ID);
$package_title = 'Pay at least $'.$minimum_price.' for these '.$podcast_count.' items';
foreach($podcasts as $podcast){
$podcast_details = get_post($podcast);
$image = get_the_post_thumbnail_url(get_the_ID(), array('250', '250'));
$image = $image?$image:wp_get_attachment_image_src(8059, 'thumbnail');
?>
<div class="col-md-3">
<div class="card <?php echo 'package-'.$get_package->ID.' podcast-'.$podcast_details->ID;?>" data-price="<?php echo $minimum_price;?>" data-packageid="<?php echo $get_package->ID;?>">
<img src="<?php echo $image[0];?>" alt="<?php echo $podcast_details->post_title; ?>" class="card-img-top">
<div class="card-body">
<h3><?php echo substr($podcast_details->post_title, 0, 20) . ' ...';?></h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
</div>
</div>
<?php }?>
</div>
</div>
</div>
</div>
</div>
<?php }
}?>
解决方案
I have to make it all HTML to see that if it works. I hope you can rewrite it back to PHP later.
<div class="row">
<div class="col-md-12">
<div class="packages_list_body">
<div class="packages_cards_inner_wrap" id="package-xxx">
<h2 id="bundle_p_title" style="color:#a52a2a; margin-left: 12px;">Title here</h2>
<div id="carouselExampleSlidesOnly" class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active group-of-cards">
<div class="packages_cards row">
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title1</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title2</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title3</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
</div>
<!--.packages_cards-->
</div>
<!--.group-of-cards-->
<div class="carousel-item group-of-cards">
<div class="packages_cards row">
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title4</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title5</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
<div class="col-md-3">
<div class="card">
<img src="https://www.gstatic.com/webp/gallery/1.jpg" alt="sample" class="card-img-top">
<div class="card-body">
<h3>Post title6</h3>
<p> Hello, This is ia test episode of Abbot and Costello hope you guys have enjoyed listening...</p>
</div>
<!--.card-body-->
</div>
<!--.card-->
</div>
<!--.col-xxx-x-->
</div>
<!--.packages_cards-->
</div>
<!--.group-of-cards-->
</div>
<!--.carousel-inner-->
</div>
<!--.carousel-->
</div>
<!--.packages_cards_inner_wrap-->
</div>
<!--.packages_list_body-->
</div>
</div>
<!--.row-->
See it in action ( https://jsfiddle.net/qt60whLf/ ).
Bootstrap 4 document ( https://getbootstrap.com/docs/4.0/components/carousel/ ).
推荐阅读
- php - 如何使用 PDO mysql 连接修复 PHP 中的“bind_param()”错误
- tensorflow - 将 tf.dataset 写回 TFRecord
- java - 使用 URI 显示图像在 Android Q 上不起作用
- json - Linkedin API:如何激活 r_basicprofile 作为权限?
- python - 如何快速轻松地在熊猫数据框中按列 [0] 的值选择单行
- flutter - 如何在 Flutter 中捕获 StreamProvider 中的错误
- api - 在 Nuxt.js 中为 API 调用注入 JWT 的最佳方法是什么?
- pandas - ImportError: 安装 anaconda 后无法导入名称 _distributor_init
- common-lisp - Common Lisp 中的变量作用域
- java - 用于 gradle 的 JLink 插件给出了找不到文件的错误