Bootstrap WordPress Carousel Recent Posts This works, but I would like suggestions to improve it. For one I think the get posts shouldn't have to be repeated twice, but it only pulls the first two posts if I don't do it this way.

Also, I think 
$incNum == 0 ? 'class="active"':'class' can be simplified, but if I take the second part out I get an error.

&lt;div class="section-title"&gt;
                    &lt;h1&gt;Most Recent Post&lt;/h1&gt;
                &lt;/div&gt;  

                    &lt;?php
                    // Get posts (tweak args as needed)
                    $i=0;
                    $incNum = 0;
                    $args = array(
                        'post_type'        =&gt; 'post',
                        'posts_per_page'   =&gt; -1,
                        'orderby' =&gt; "date",
                        'order' =&gt; "desc"
                    );
                    $posts = get_posts( $args );
                ?&gt;



                   &lt;div id="recent-post-carousel" class="carousel slide" data-ride="carousel"&gt;
                    &lt;ol class="carousel-indicators"&gt;
                        &lt;?php foreach (array_chunk($posts, 4, true) as $posts) :  ?&gt;
                        &lt;?php echo( '&lt;li data-target="#recent-post-carousel" data-slide-to="'.$incNum.'"'.($incNum == 0 ? 'class="active"':'class').'&gt;&lt;/li&gt;'); 
                        $incNum++;
                        ?&gt;

                    &lt;?php endforeach; ?&gt;

                    &lt;/ol&gt;
                    &lt;div class="carousel-inner"&gt;



                               &lt;?php
                    // Get posts (tweak args as needed)
                    $i=0;
                    $incNum = 0;
                    $args = array(
                        'post_type'        =&gt; 'post',
                        'posts_per_page'   =&gt; -1,
                        'orderby' =&gt; "date",
                        'order' =&gt; "desc"
                    );
                    $posts = get_posts( $args );
                ?&gt;





                &lt;?php foreach (array_chunk($posts, 4, true) as $posts) :  ?&gt;
                &lt;div class="item &lt;?php if ($i==0){echo 'active';}?&gt;"&gt;            
                    &lt;div class="row"&gt;

                        &lt;?php foreach( $posts as $post ) : setup_postdata($post); ?&gt;

                           &lt;div class="col-sm-6 post-fix"&gt;
                                    &lt;div class="single-post "&gt;
                                        &lt;div class="pull-left post-image"&gt;
                                            &lt;a href="#"&gt;
                                                &lt;?php the_post_thumbnail( 'full' );  ?&gt;
                                                &lt;i class="fa fa-angle-right"&gt;&lt;/i&gt;
                                            &lt;/a&gt;
                                        &lt;/div&gt;
                                        &lt;div class="pull-right post-details"&gt;
                                            &lt;p class="post-date"&gt;03 Dec 2014&lt;/p&gt;
                                            &lt;p&gt;&lt;?php echo $i?&gt;&lt;/p&gt;

                                            &lt;a href="#"&gt;&lt;h5&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="&lt;?php the_title(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;
                            &lt;/h5&gt;&lt;/a&gt;
                                            &lt;span&gt;John doe&lt;/span&gt;
                                            &lt;p&gt;&lt;?php echo substr(get_the_excerpt(), 0,99).' [...]'; ?&gt;&lt;/p&gt;
                                        &lt;/div&gt;
                                    &lt;/div&gt;
                                &lt;/div&gt;
                        &lt;?php $i++ ?&gt;

                        &lt;?php endforeach; ?&gt;

                    &lt;/div&gt;

                        &lt;/div&gt;

                &lt;?php endforeach; ?&gt;
I haven't ran (don't have a WordPress installation handy) or debugged the code, but this should work. Your original code is buggy in a number of ways. The $posts variable is clobbered when you use it as the iterating variable in the foreach loop, which is probably why your code wasn't working as expected. 

&lt;div class="section-title"&gt;
  &lt;h1&gt;Most Recent Post&lt;/h1&gt;
&lt;/div&gt;

&lt;?php
  // Use a variable instead of magic number. Consider moving this to a WordPress config instead using get_option
  $chunk_size = 4;
  $args = array(
    'post_type'         =&gt; 'post',
    'posts_per_page'    =&gt; -1,
    'orderby'           =&gt; "date",
    'order'             =&gt; "desc"
  );
  $posts = get_posts( $args );
?&gt;

&lt;div id="recent-post-carousel" class="carousel slide" data-ride="carousel"&gt;
  &lt;ol class="carousel-indicators"&gt;
    &lt;?php // Use a for loop here instead of foreach, since you don't actually need the contents of the array ?&gt;
    &lt;?php for ($i = 0, $l = ceil(count($posts) / $chunk_size); $i &lt; $l; $i++):  ?&gt;
      &lt;li data-target="#recent-post-carousel" data-slide-to="&lt;?php echo $i ?&gt;" &lt;?php echo ($i === 0 ? 'class="active"' : '') ?&gt;&gt;&lt;/li&gt;
    &lt;?php endfor; ?&gt;
  &lt;/ol&gt;
  &lt;div class="carousel-inner"&gt;
  &lt;?php foreach (array_chunk($posts, $chunk_size) as $i =&gt; $chunk) :  ?&gt;
    &lt;div class="item &lt;?php if ($i === 0){echo 'active';}?&gt;"&gt;
      &lt;div class="row"&gt;
        &lt;?php foreach( $chunk as $p =&gt; $post ): setup_postdata($post); ?&gt;
          &lt;div class="col-sm-6 post-fix"&gt;
            &lt;div class="single-post "&gt;
              &lt;div class="pull-left post-image"&gt;
                &lt;?php // href here should probably be the_permalink() ?&gt;
                &lt;a href="#"&gt;
                  &lt;?php the_post_thumbnail( 'full' );  ?&gt;
                  &lt;i class="fa fa-angle-right"&gt;&lt;/i&gt;
                &lt;/a&gt;
              &lt;/div&gt;
              &lt;div class="pull-right post-details"&gt;
                &lt;?php // Post date shouldn't be hard coded ?&gt;
                &lt;p class="post-date"&gt;03 Dec 2014&lt;/p&gt;
                &lt;p&gt;&lt;?php echo $i*$chunk_size + $p?&gt;&lt;/p&gt;
                &lt;h5&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark" title="&lt;?php the_title(); ?&gt;"&gt;
                    &lt;?php the_title(); ?&gt;&lt;/a&gt;
                &lt;/h5&gt;
                &lt;?php // Post author shouldn't be hard coded ?&gt;
                &lt;span&gt;John doe&lt;/span&gt;
                &lt;?php // Consider using wp_trim_excerpt() instead ?&gt;
                &lt;p&gt;&lt;?php echo substr(get_the_excerpt(), 0, 99).' [...]'; ?&gt;&lt;/p&gt;
              &lt;/div&gt;
            &lt;/div&gt;
          &lt;/div&gt;
        &lt;?php endforeach; ?&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;?php endforeach; ?&gt;
  &lt;/div&gt;
&lt;/div&gt;


A few things to note here: 


Use foreach( $array as $i =&gt; $element) instead of keeping track of $i separately. 
Post count is calculated using $i*$chunk_size + $p 
Your HTML was buggy in a few places. I cleaned it up, and left comments in the places where there are probably bugs 
Format your code properly to make it more readable 
Consider using short tags &lt;?= ?&gt; to replace &lt;?php echo ?&gt; to improve readability 
Try to use WordPress functions instead of rolling your own. That way plugins can also hook into them