我正在转换一个静态的html网站到动态的php,我有一个<ol>,其中<li>是静态添加的,即用户评价,当添加一个新的评价时,我需要的列表自动递增。也就是说,如果一个人证明了子弹应该是,那么2的子弹就是2,以此类推。我的html代码是:
<ol class="carousel-indicators new">
<li data-target="#quote-carousel" data-slide-to="0" class="active"></li>
<li data-target="#quote-carousel" data-slide-to="1"></li>
<li data-target="#quote-carousel" data-slide-to="2"></li>
</ol>#quote-carousel是证明幻灯片的id
<div class="carousel slide" data-ride="carousel" id="quote-carousel">
<!-- Carousel Slides / Quotes -->
<div class="carousel-inner">
<?php
$args = array(
'post_type' => 'testimonials_post'
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$i = 1;
$bullets="";
while ( $the_query->have_posts() ) {
$the_query->the_post();
$post_id = get_the_ID();
$post_title = get_the_title($post_id);
$post_content = get_the_content($post_id);
$featured_img_url = get_the_post_thumbnail_url($post_id, 'medium');
?>
<div class="item <?php echo $the_query->current_post >= 1 ? '' : 'active'; ?> text-center">
<div class="row">
<div class="col-sm-12">
<img src="<?php echo $featured_img_url; ?>" class="img-o">
<?php echo $post_content; ?>
<small><strong><?php echo $post_title; ?></strong></small>
</div>
</div>
</div>
<?php
$activeclass="";
if($i==1){
$activeclass='class="active"';
}
$bullets.='<li data-target="#quote-carousel" data-slide-to="'.($i-1).'" '.$activeclass.'></li>';
$i++;
}
}
wp_reset_query();
?>
</div>
<!-- Bottom Carousel Indicators -->
<ol class="carousel-indicators new">
<?php
echo $bullets;
?>
</ol>
</div>发布于 2019-12-01 18:26:01
<div class="carousel slide" data-ride="carousel" id="quote-carousel">
<!-- Carousel Slides / Quotes -->
<div class="carousel-inner">
<?php
$args = array(
'post_type' => 'testimonials_post'
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
$i = 1;
$bullets="";
while ( $the_query->have_posts() ) {
$the_query->the_post();
$post_id = get_the_ID();
$post_title = get_the_title($post_id);
$post_content = get_the_content($post_id);
$featured_img_url = get_the_post_thumbnail_url($post_id, 'medium');
?>
<div class="item <?php echo $the_query->current_post >= 1 ? '' : 'active'; ?> text-center">
<div class="row">
<div class="col-sm-12">
<img src="<?php echo $featured_img_url; ?>" class="img-o">
<?php echo $post_content; ?>
<small><strong><?php echo $post_title; ?></strong></small>
</div>
</div>
</div>
<?php
$activeclass="";
if($i==1){
$activeclass='class="active"';
}
$bullets.='<li data-target="#quote-carousel" data-slide-to="'.($i-1).'" '.$activeclass.'></li>';
$i++;
}
}
wp_reset_query();
?>
</div>
<!-- Bottom Carousel Indicators -->
<ol class="carousel-indicators new">
<?php
echo $bullets;
?>
</ol>
</div>https://stackoverflow.com/questions/59123888
复制相似问题