WordPress传送带幻灯片无法工作

时间:2019-02-22 作者:Shaibu Stephen Ojate

有人能帮我弄清楚我到底哪里做错了吗?幻灯片根本不起作用

     <!-- Carousel Card -->
                <div class="card card-raised card-carousel">
                    <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel" data-interval="3000">
                      <ol class="carousel-indicators">
                        <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
                        <li data-target="#carouselExampleIndicators" data-slide-to="1" class=""></li>
                        <li data-target="#carouselExampleIndicators" data-slide-to="2" class=""></li>
                      </ol>

                      <?php $paged=(get_query_var(\'paged\'))? absint (get_query_var(\'paged\')):1;
                        $args=array(\'post_type\'=>\'slide\',
                        \'post_per_page\'=>1,
                        \'paged\'=>$paged);
                        $slideshow=new WP_Query ($args);
                        ?>                         
                     <?php while($slideshow->have_post()): $slideshow->the_post();?>

                      <div class="carousel-inner" role="checkbox">
                        <div class="carousel-item active">
                          <?php echo get_post_thumbnail(); ?> 
                          alt="First slide">
                          <div class="carousel-caption d-none d-md-block">
                            <h4>
                                <i class="material-icons"><?php the_title(); ?></i>
                               <?php the_excerpt(); ?>
                            </h4>
                          </div>
                        </div>
                        <?php endwhile; wp_reset_query();?>


                        <?php $paged=(get_query_var(\'paged\'))? absint (get_query_var(\'paged\')):1;
                        $args=array(\'post_type\'=>\'slide\',
                        \'post_per_page\'=>-1,
                        \'offset\'=>1,
                        \'paged\'=>$paged);
                        $slideshow=new WP_Query ($args);
                        ?>

                     <?php while($slideshow->have_post()): $slideshow->the_post();?>
                        <div class="carousel-item">
                           <?php echo get_post_thumbnail(); ?> 
                          <div class="carousel-caption d-none d-md-block">
                            <h4>
                                <i class="material-icons"><?php the_title(); ?></i>                   
                            </h4>
                          </div>
                        </div>
                         <?php endwhile; wp_reset_query();?>


                        <?php $paged=(get_query_var(\'paged\'))? absint (get_query_var(\'paged\')):1;
                        $args=array(\'post_type\'=>\'slide\',
                        \'post_per_page\'=>-1,
                        \'offset\'=>1,
                        \'paged\'=>$paged);
                        $slideshow=new WP_Query ($args);
                        ?>

                     <?php while($slideshow->have_post()): $slideshow->the_post();?>
                        <div class="carousel-item">
                            <?php echo get_post_thumbnail(); ?> 
                          <div class="carousel-caption d-none d-md-block">
                            <h4>
                                <i class="material-icons"><?php the_title(); ?></i>
                            </h4>
                          </div>
                        </div>
                         <?php endwhile; wp_reset_query();?>
                      </div>
                      <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
                        <i class="material-icons">keyboard_arrow_left</i>
                        <span class="sr-only">Previous</span>
                      </a>
                      <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
                        <i class="material-icons">keyboard_arrow_right</i>
                        <span class="sr-only">Next</span>
                      </a>
                    </div>
                </div>
                <!-- End Carousel Card -->
功能。php

function cptui_register_my_cpts() {

    /**
     * Post Type: slide.
     */

    $labels = array(
        "name" => __( "slide", "oiza" ),
        "singular_name" => __( "slide", "oiza" ),
    );

    $args = array(
        "label" => __( "slide", "oiza" ),
        "labels" => $labels,
        "description" => "",
        "public" => true,
        "publicly_queryable" => true,
        "show_ui" => true,
        "delete_with_user" => false,
        "show_in_rest" => true,
        "rest_base" => "",
        "rest_controller_class" => "WP_REST_Posts_Controller",
        "has_archive" => false,
        "show_in_menu" => true,
        "show_in_nav_menus" => true,
        "exclude_from_search" => false,
        "capability_type" => "post",
        "map_meta_cap" => true,
        "hierarchical" => true,
        "rewrite" => array( "slug" => "slide", "with_front" => true ),
        "query_var" => true,
        "supports" => array( "title", "editor", "thumbnail", "author" ),
    );

    register_post_type( "slide", $args );
}

add_action( \'init\', \'cptui_register_my_cpts\' );

1 个回复
SO网友:Tanmay Patel

使用以下代码。我用发问者的代码修改了下面的代码。现在它正在工作。

<div id="carousel" class="carousel slide" data-ride="carousel"  data-interval="3000"> 
  <!-- Carousel items -->
  <div class="carousel-inner">
    <?php $slider = new WP_Query(array(
        \'post_type\' => \'slide\',
        \'posts_per_page\'    => -1,
    )); ?>
    <?php 
    if ( have_posts() ) {
        $x=0;
        while ( $slider->have_posts() ) {
            $x++;
            $slider->the_post(); ?>
            <div class="<?php if($x==1){echo \'active\';} ?> item">
              <?php if ( has_post_thumbnail() ) : ?>
              <?php the_post_thumbnail(); ?>
              <div class="carousel-caption d-none d-md-block">
                <h4> <i class="material-icons">
                  <?php the_title(); ?>
                  </i> </h4>
              </div>
              <?php endif; ?>
            </div>
        <?php } // end while
    } // end if
    ?>
  </div>
  <!-- Carousel nav -->
  <ol class="carousel-indicators">
    <?php for($i=0; $i<$x; $i++ ) { ?>
    <li data-target="#carousel" data-slide-to="<?php echo $i;  ?>" class="<?php if($i==0){ echo \'active\'; }?>"></li>
    <?php } ?>
  </ol>
  <a class="left carousel-control" href="#carousel" role="button" data-slide="prev"> <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a>
  <a class="right carousel-control" href="#carousel" role="button" data-slide="next"> <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span> <span class="sr-only">Next</span> </a>
</div>

相关推荐

Sidebar slideshow widget

有人知道可以放在边栏上的高质量图像幻灯片小部件吗?