I have integrated the bootstrap carousel into my wordpress. Slides will be taken from pages, there will be a page called carousel and it will have subpages where post-thumbnails will be taken. I'm still not very good at cms wordpress someone help me please Below is my code:
<div >
<div id="carouselExampleIndicators" data-ride="carousel">
<ol >
<li data-target="#carouselExampleIndicators" data-slide-to="0" ></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div >
<?php
$args = array( [
'hierarchical' => 1,
'child_of' => 5,
'parent' => -1,
'post_type' => 'page',
'post_status' => 'publish',
] );
$pages = get_pages( $args );
foreach( $pages as $post ){
setup_postdata( $post );
?>
<div >
<?php the_post_thumbnail('direction-carousel', '') ?>
<img src="" alt="Первый слайд">
</div>
<?php endwhile; wp_reset_postdata(); ?>
<?php
$args = array( [
'hierarchical' => 1,
'child_of' => 5,
'parent' => -1,
'post_type' => 'page',
'post_status' => 'publish',
] );
$pages = get_pages( $args );
foreach( $pages as $post ){
setup_postdata( $post );
?>
<div >
<?php the_post_thumbnail('direction-carousel', '') ?>
</div>
<?php endwhile; wp_reset_postdata(); ?>
</div>
</div>
<a href="#carouselExampleIndicators" role="button" data-slide="prev">
<span aria-hidden="true"></span>
<span >Previous</span>
</a>
<a href="#carouselExampleIndicators" role="button" data-slide="next">
<span aria-hidden="true"></span>
<span >Next</span>
</a>
</div>
CodePudding user response:
I sort of figured out the code, but for some reason an error pops up: Parse error: syntax error, unexpected token ":"
<?php
$i = 0;
$pages = get_pages([
'hierarchical' => 1,
'child_of' => 5,
'parent' => -1,
'post_type' => 'page',
'post_status' => 'publish',
]);?>
<div >
<div id="carouselExampleIndicators" data-ride="carousel">
<ol >
<?php for($i = 0; $i < count($pages); $i):
?>
<li data-target="#carouselExampleIndicators" data-slide-to="<?= $i;?>"<?=($i==0 ? ' ' : '');?>></li>
<?php endfor;
$i = 0;
?>
</ol>
<div >
<?php
foreach( $pages as $post ):
setup_postdata( $post ); ?>
<div >
<?php the_post_thumbnail('direction-carousel', '') ?>
</div>
<?php
$i;
endforeach;
wp_reset_postdata();
?>
</div>
</div>
CodePudding user response:
Try:
<?php
$i = 0;
$pages = get_pages([
'hierarchical' => 1,
'child_of' => 5,
'parent' => -1,
'post_type' => 'page',
'post_status' => 'publish',
]);?>
<div >
<div id="carouselExampleIndicators" data-ride="carousel">
<ol >
<?php for($i = 0; $i < count($pages); $i):
?>
<li data-target="#carouselExampleIndicators" data-slide-to="<?= $i;?>"<?=($i==0 ? ' ' : '');?>></li>
<?php endfor;
$i = 0;
?>
</ol>
<div >
<?php
foreach( $pages as $post ):
setup_postdata( $post ); ?>
<div >
<?php the_post_thumbnail('direction-carousel', '') ?>
</div>
<?php
$i;
endforeach;
wp_reset_postdata();
?>
</div>
</div>