<?php get_header() ?>

<?php if ( have_posts() ) { ?>

  <section id="content" class="articles wrapper container">
    <header <?php post_class('section-header'); ?>>
      <h1 class="title"><?php echo get_the_title(get_option('page_for_posts')); ?></h1>
    </header>
    <?php
      /*
      * @Sidebar Content before
      */
      get_sidebar('content-before'); ?>
    <div class="inner">

    <?php while ( have_posts() ) : the_post() ?>

    <?php
      $post_type = get_post_type();
      $post_meta = get_post_custom();
      $more_text = sandbox_get_more_text($post_type, $post_meta);

      // echo var_dump(!empty($customPostsMeta["_custom_more_text"]));
      $excerpt = apply_filters('the_content', has_excerpt() ? get_the_excerpt() : wp_trim_words(get_the_content(), 40));

      // post thumbnail as background image
      $thumbnail_style = '';
      if ( has_post_thumbnail() ) {
        $thumbnail_style = ' style="background-image:url(' . get_the_post_thumbnail_url($post_id, 'full') . ');"';
      }
    ?>

    <article id="post-<?php the_ID() ?>" <?php post_class(); ?>>
      <div class="inner">
      <?php if ( has_post_thumbnail() ) { ?>
        <a href="<?php the_permalink() ?>" class="post-thumbnail"<?php echo $thumbnail_style; ?>><?php the_post_thumbnail('sandbox-default'); ?></a>
      <?php } ?>
        <div class="content">
          <h2 class="title"><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></h2>
				  <?php echo $excerpt; ?>
          <a class="button" href="<?php the_permalink() ?>"><?php printf($more_text); ?></a>
        <?php if ( $meta = sandbox_get_meta_data(array('rtime', 'date', 'author', 'terms')) ) { ?>
          <ul class="meta">
            <?php echo $meta; ?>
          </ul>
        <?php } ?>
        </div>
      </div>
	  </article><!-- .post -->

    <?php endwhile; ?>

      <?php if ( function_exists('wp_pagenavi') ) {

      	wp_pagenavi(); // http://wordpress.org/plugins/wp-pagenavi/

      } else {

      ?>

		    <nav id="nav-below" class="navigation">
			    <div class="nav-previous"><?php next_posts_link( __( '<span class="meta-nav">&laquo;</span> Older results', 'sandbox' ) ) ?></div>
			    <div class="nav-next"><?php previous_posts_link( __( 'Newer results <span class="meta-nav">&raquo;</span>', 'sandbox' ) ) ?></div>
		    </nav>

      <?php } ?>
    </div>
    <?php
      /*
      * @Sidebar Content after
      */
      get_sidebar('content-after'); ?>
	</section>

<?php } ?>

<?php get_footer() ?>
