php - Bootstap Carousel does not work with wp_get_recent_posts() function -


good day gentelmen, faced issue can not solve long time. problem when try use wp_get_recent_posts() inside foreach loop not seem working instead shows empty block.

    <div id="awesome-carousel" class="carousel slide" data-ride="carousel">        <!-- wrapper slides -->       <div class="carousel-inner" role="listbox">          <?php                $count = 0;             $post_p = wp_get_recent_posts();             foreach($post_p $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> 

in advice.

the problem in structure, implemented wp_query object , add condition $lastblog->have_posts() in while loop.

$categories = get_categories(); $count = 0; $bullets = ''; foreach($categories $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; 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -