Php 引导转盘不适用于wp_get_recent_posts()函数
我面临着一个长期无法解决的问题。 问题是,当我尝试在foreach循环中使用wp_get_recent_posts()时,它似乎不起作用,而是显示空块Php 引导转盘不适用于wp_get_recent_posts()函数,php,html,wordpress,twitter-bootstrap,Php,Html,Wordpress,Twitter Bootstrap,我面临着一个长期无法解决的问题。 问题是,当我尝试在foreach循环中使用wp_get_recent_posts()时,它似乎不起作用,而是显示空块 <div class="row"> <div class="col-xs-12"> <div id="awesome-carousel" class="carousel slide" data-ride="carousel"> <!-- Wrapper for slides
<div class="row">
<div class="col-xs-12">
<div id="awesome-carousel" class="carousel slide" data-ride="carousel">
<!-- Wrapper for slides -->
<div class="carousel-inner" role="listbox">
<?php
$count = 0;
$post_p = wp_get_recent_posts();
foreach($post_p as $post):
if( have_posts() ):
while( have_posts() ): the_post(); ?>
<div class="item <?php if($count == 0): echo 'active'; endif; ?>">
<?php the_post_thumbnail('full'); ?>
<div class="carousel-caption">
<?php the_title( sprintf('<h1 class="entry-title"><a href="%s">', esc_url( get_permalink() ) ),'</a></h1>' ); ?>
<small><?php the_category(' '); ?></small>
</div>
</div>
<?php $bullets .= '<li data-target="#awesome-carousel" data-slide-to="'.$count.'" class="'; ?>
<?php if($count == 0): $bullets .='active'; endif; ?>
<?php $bullets .= '"></li>'; ?>
<?php endwhile;
endif;
wp_reset_postdata();
$count++;
endforeach;
?>
<!-- Indicators -->
<ol class="carousel-indicators">
<?php echo $bullets; ?>
</ol>
</div>
<!-- Controls -->
<a class="left carousel-control" href="#awesome-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="#awesome-carousel" role="button" data-slide="next">
<span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
</div>
</div>
问题出在结构上,我实现了WP_查询对象,并在while循环中添加了条件$lastBlog->have_posts()
$categories = get_categories();
$count = 0;
$bullets = '';
foreach($categories as $category):
$args = array(
'type' => 'post',
'posts_per_page' => 1,
'category__in' => $category->term_id,
'category__not_in' => array( 10 ),
);
$lastBlog = new WP_Query( $args );
if( $lastBlog->have_posts() ):
while( $lastBlog->have_posts() ): $lastBlog->the_post(); ?>
<div class="item <?php if($count == 0): echo 'active'; endif; ?>">
<?php the_post_thumbnail('full'); ?>
<div class="carousel-caption">
<?php the_title( sprintf('<h1 class="entry-title"><a href="%s">', esc_url( get_permalink() ) ),'</a></h1>' ); ?>
<small><?php the_category(' '); ?></small>
</div>
</div>
<?php $bullets .= '<li data-target="#awesome-carousel" data-slide-to="'.$count.'" class="'; ?>
<?php if($count == 0): $bullets .='active'; endif; ?>
<?php $bullets .= '"></li>'; ?>
<?php endwhile;
endif;
wp_reset_postdata();
$count++;
endforeach;
$categories=get_categories();
$count=0;
$子弹='';
foreach($类别作为$类别):
$args=数组(
'type'=>'post',
“每页帖子数”=>1,
'category\u in'=>$category->term\u id,
'类别不在'=>数组中(10),
);
$lastBlog=新的WP\u查询($args);
如果($lastBlog->have_posts()):
而($lastBlog->have_posts()):$lastBlog->the_post();?>
如果打印($posts\p),它可能会被一个元素(reponseData或某种元素)包装,从而导致循环不起作用