我正在尝试创建一个引导式旋转木马,将特色图像作为div中的背景。它适用于第一篇文章,但第二篇文章没有加载正确的背景(它加载第一篇文章中的背景)。
Code:
<div class="jumbotron jumbotron-header grey-dark">
<div id="myCarousel2" class="carousel slide" data-ride="carousel" data-interval="false">
<div class="carousel-inner" role="listbox">
<?php
$queryObject = new Wp_Query( array(
\'showposts\' => 5,
\'post_type\' => array(\'slider\'),
\'orderby\' => 1
));
// The Loop
if ( $queryObject->have_posts() ) :
$i = 0;
while ( $queryObject->have_posts() ) :
$queryObject->the_post();
if ( $i == 0 ) : ?>
<?php global $post; ?>
<?php
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, \'\' );
?>
<div class="item jumbotron-content active" style="background-image:url(\'<?php echo $src[0]; ?>\');width: 100%;height: 500px;display: cover;background-position: center center; background-repeat: no-repeat;background-size: cover;">
<div class="container">
<h2><?php the_title();?><h2>
</div>
</div>
<?php endif;
if ( $i != 0 ) : ?>
<div class="item jumbotron-content" style="background-image:url(\'<?php echo $src[0]; ?>\');width: 100%;height: 500px;display: cover;background-position: center center; background-repeat: no-repeat;background-size: cover;">
<div class="container">
<h2><?php the_title();?><h2>
</div>
</div>
<?php endif; ?>
<?php $i++;
endwhile;
endif;
?>
有人知道我做错了什么吗?提前感谢!
最合适的回答,由SO网友:rwzdoorn 整理而成
已解决问题:
必须在endif后添加相同的全球职位:
<?php endif;
if ( $i != 0 ) : ?>
<?php global $post; ?>
<?php
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), array( 5600,1000 ), false, \'\' );
?>