WordPress Count posts within a custom post type

It looks that this code is very old. Function wp_start() is deprecated since WordPress 1.5 (Documentation). But you wanted to know how it code is counting so:

  • $posts = get_posts('numberposts=6&offset=0'); – get 6 posts
  • foreach ($posts as $post) : – iterate over each post
  • static $count1 = 0; – initializes $count1 variable
  • $count1++; – increase counter by one

What is more, this code will not count, because init of counter variable is inside loop. Over each iteration value of this variable will be set to 0. Only at the end value will be 1. Also counter is unnecessary, because you are querying for 6 posts, and then in code you have got break when counter is equal to 6. Your code should looks like this:

<?php $query = new WP_Query( array(
    'numberposts' => 6,
    'offset' => 0
) ); ?>

<?php if ( $query->have_posts() ): ?>
    <?php while ( $query->have_posts() ): ?>
        <?php $query->the_post(); ?>
        <div class="col-md-4 com-xs-12 pannel">
            <div class="pannel-news">
                <?php the_post_thumbnail(); ?>
                <div class="sidebar-color">
                    <strong>
                        <a href="https://wordpress.stackexchange.com/questions/233430/<?php the_permalink(); ?>">
                            <?php the_title( '<h4>', '</h4>' ); ?>
                        </a>
                    </strong>
                </div>
            </div>
        </div>
    <?php endwhile; ?>
<?php endif; ?>