<?php
/*
 Template Name: Blog List
 Template Description: Template for displaying Post Type blog listing with configurable sidebar.
 Post Types: page
*/
?>
<?php get_header(); ?>

  <div id="maincontent" class="area clearfix animated in fadeInLeft startblank">
    <div class="container-fluid">
      <div class="row">

        <div id="content"
             class="region items
           <?php echo VTCore_Zeus_Utility::getColumnSize('content'); ?>
           with-sidebar-<?php echo VTCore_Zeus_Utility::getSidebar('teaser'); ?>"
          >

          <?php
          // Build the sticky posts
          $sticky = get_option('sticky_posts', array());
          if (!empty($sticky)) {

            rsort($sticky);

            $sticky_query = VTCore_Zeus_Utility::getPosts(array(
                'post__in' => $sticky,
                'ignore_sticky_posts' => FALSE,
                'post_type' => 'post'
              ));
            $sticky_posts = $sticky_query->get_posts();

            foreach ($sticky_posts as $post) {

              setup_postdata($post);
              get_template_part('templates/content/teaser', get_post_format($post));

            }

            wp_reset_postdata();
          }


          // Build the main loop
          $args = array(
            'post_type' => 'post',
            'posts_per_page' => get_option('posts_per_page'),
            'paged' => isset($_GET['paged_main']) ? $_GET['paged_main'] : 1
          );
          if (!empty($sticky)) {
            $args['post__not_in'] = $sticky;
          }

          $query = VTCore_Zeus_Utility::getPosts($args);
          $posts = $query->get_posts();

          if (!empty($posts)) {
            foreach ($posts as $post) {

              setup_postdata($post);
              get_template_part('templates/content/teaser', get_post_format($post));

            }

            wp_reset_postdata();

            // Retrieves Pager
            $pager = VTCore_Zeus_Utility::getPager($query, FALSE, 'main');
            if (!empty($pager)) {
              echo '<div class="pagination pagination-left">' . $pager . '</div>';
            }

          }

          // Throw page not found if we got no valid posts
          else {
            get_template_part('templates/content/empty');
          }

          ?>
        </div>

        <?php
        // Build sidebar.
        if (VTCore_Zeus_Utility::getSidebar('teaser') == 'right'
          || VTCore_Zeus_Utility::getSidebar('teaser') == 'left'
        ) {
          get_sidebar('sidebar');
        }
        ?>

      </div>
    </div>
  </div>
<?php get_footer(); ?>