can somebody help me out on where i got the thing whole wrong? The slide is not working at all
<!-- 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 -->
functions.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' );
can somebody help me out on where i got the thing whole wrong? The slide is not working at all
<!-- 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 -->
functions.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' );
Share
edited Feb 22, 2019 at 5:36
fuxia♦
107k39 gold badges255 silver badges461 bronze badges
asked Feb 22, 2019 at 3:09
Shaibu Stephen OjateShaibu Stephen Ojate
11 bronze badge
1
- Can you share with me actual page link where you have displayed the carousel slide. so I can check it and will help you to fix this issue. – Tanmay Patel Commented Feb 22, 2019 at 4:06
1 Answer
Reset to default 1Use this below code. I have done this below code with some modification with Questioner's code. Now it is working.
<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>