<?php
/**
 * The template for displaying the BXSlider
 *
 * @package WordPress
 * @subpackage MyArcadeTheme
 * @since 1.0.0
 */

// Check if the slider is enabled
if ( myarcadetheme_get_option( 'slider_home' ) ) {

  $categories = myarcadetheme_get_option( 'categories_sliderft' );
  $category_in = '';
  if ( !empty($categories) ) {
    $category_in = implode(",", $categories);
  }

  // Query games with screenshots
  $args = array (
    'showposts' => myarcadetheme_get_option( 'gamecount_sliderft', 10 ),
    'cat'       => $category_in,
    'orderby'   => 'date',
    'tag'       => myarcadetheme_mobile_tag(),
    'meta_query' => array (
      array (
        'key' => 'mabp_screen1_url',
        'value' => 'http',
        'compare' => 'LIKE'
      )
    )
  );

  $querybxslider = new WP_Query( $args );

  if ( $querybxslider->have_posts() ) {
    global $post;

    $queried_posts = array();

    ob_start();
    ?>
    <div class="lastgms-cn-clfl">
      <div class="mt-bx-loading"></div>
      <div id="lastgmsload" style="visibility:hidden">
        <div class="lstgms">
          <ul class="sldr-gm">
          <?php while ( $querybxslider->have_posts() ) : $querybxslider->the_post(); ?>
            <?php $queried_posts[] = $post->ID; ?>
            <!--<game>-->
            <li>
              <div class="gmcn-sldr" itemscope="itemscope" itemtype="http://schema.org/Article">
                <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" itemprop="url">
                  <figure itemprop="image"><?php myarcade_screenshot( array( 'width' => 750, 'height' => 390 ) ); ?></figure>
                </a>
                <div class="gm-text">
                  <div class="gm-cate"><?php echo get_the_category_list(' '); ?></div>
                  <div class="gm-titl" itemprop="name">
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>" itemprop="url">
                      <?php the_title(); ?>
                    </a>
                  </div>
                  <div class="gm-desc" itemprop="description">
                    <p><?php myarcade_description(150); ?></p>
                  </div>

                  <?php myarcadetheme_rate_and_view(); ?>
              </div>
            </li>
            <!--</game>-->
          <?php endwhile; ?>
          <?php wp_reset_query(); ?>
          </ul>
        </div>
        <ul class="lst-gamgrid vs-dsk">
          <?php
          // Query latest games for the right site of the slider, but exclude already displayed in the slider
          $args = array (
            'showposts' => 9,
            'cat'       => $category_in,
            'post__not_in' => $queried_posts,
            'orderby'   => 'date',
          );

          $additional_games = new WP_Query( $args );

          if ( $additional_games->have_posts() ) {
            while ( $additional_games->have_posts() ) : $additional_games->the_post();
              ?>
              <!--<game>-->
              <li>
                <div class="gmcn-midl">
                  <figure class="gm-imag">
                    <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                      <?php myarcade_thumbnail( array( 'width' => 130, 'height' => 130, 'lazy_load' => myarcadetheme_get_option('lazy_load') ) ); ?>
                    </a>
                  </figure>
                  <div class="gm-text">
                    <div class="gm-cate"><?php echo get_the_category_list(' '); ?></div>
                    <div class="gm-titl">
                      <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>">
                        <?php myarcade_title(25); ?>
                      </a>
                    </div>

                    <?php myarcadetheme_rate_and_view(); ?>
                  </div>
                </div>
              </li>
              <!--</game>-->
              <?php
            endwhile;
            wp_reset_query();
          }
          ?>
        </ul>
      </div>
    </div>
    <?php
    ob_end_flush();
  }
}