首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在php中从静态列表生成动态列表

问在php中从静态列表生成动态列表
EN

Stack Overflow用户
提问于 2019-12-01 16:34:02
回答 1查看 37关注 0票数 0

我正在转换一个静态的html网站到动态的php,我有一个<ol>,其中<li>是静态添加的,即用户评价,当添加一个新的评价时,我需要的列表自动递增。也就是说,如果一个人证明了子弹应该是,那么2的子弹就是2,以此类推。我的html代码是:

代码语言:javascript
复制
<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

代码语言:javascript
复制
<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>
EN

回答 1

Stack Overflow用户

发布于 2019-12-01 18:26:01

代码语言:javascript
复制
<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>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59123888

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档