<?php
/*
Template Name: NEWS paper layout
*/
GLOBAL $swift_options;
get_header(); 
?>

<div id="content"  class="full-width" role="main">
<!-- First row, Popular posts, slider+random posts, recent posts -->
	<div class="fivecol-one"> 
	<div class="div-content">
		<p class="np-popular np-section-title"><?php echo $swift_options['np_popular_posts_title']?></p>					
<?php	function filter_where( $where = '' ) {
			GLOBAL $swift_options;
			// posts in the last X days
			$where .= " AND post_date > '" . date('Y-m-d', strtotime('-'.$swift_options['np_popular_posts_age'].' days')) . "'";
			return $where;
		}

		add_filter( 'posts_where', 'filter_where' );
			
		$r = new WP_Query(array('posts_per_page' => $swift_options['np_popular_posts_number'], 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true, 'orderby' => 'comment_count', 'order' => 'DESC'));
			
		remove_filter( 'posts_where', 'filter_where' );
			
		if ($r->have_posts()) :
?>
		<ul id="np-popular">
		<?php  while ($r->have_posts()) : $r->the_post(); ?>
		<li>
			<h3 class="post-title"><a href="<?php the_permalink() ?>" title="<?php echo esc_attr(get_the_title() ? get_the_title() : get_the_ID()); ?>"><?php if ( get_the_title() ) the_title(); else the_ID(); ?></a>
			</h3><p class="date"><a href="<?php echo esc_url( get_permalink() )?>" title="<?php echo esc_attr( get_the_time() )?>" rel="bookmark"><time class="entry-date" datetime="<?php echo esc_attr( get_the_date( 'c' ) )?>" pubdate="pubdate"><?php echo esc_html( get_the_date() )?></time></a></p>
		</li>
		<?php endwhile; ?>
		</ul>
<?php 	endif;?>
<?php wp_reset_query(); ?>
	</div>
	</div>
		
	<div class="fivecol-four">
	<div class="div-content">

		<div class="fivecol-three">		
		<div class="div-content alpha"> 
<?php 		get_template_part( 'lib/includes/np-slider');?>

			<p class="np-section-title"><?php echo $swift_options['np_slider_below_title']?></p>

<?php		$args = array('posts_per_page' => $swift_options['np_slider_below_posts_number'], 'no_found_rows' => true, 'ignore_sticky_posts' => true,'post_status' => 'publish');
			if( $swift_options['np_slider_below_cats'] == -1){
				$args['orderby'] = 'rand';
			}elseif($swift_options['np_slider_below_cats'] != -2){
				$args['cat'] = $swift_options['np_slider_below_cats'];
			}
	
			$r = new WP_Query($args);
			if ($r->have_posts()) :while ($r->have_posts()) : $r->the_post(); 
?>	
			<h4 class="post-title"><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></h4>		
			<?php  the_post_thumbnail( array(100, 62), array('class' => 'alignleft np-recent' )); echo substr(get_the_excerpt(),0,160);?>
			<div class="clear"></div>
								
<?php 		endwhile;endif;?>
<?php 		wp_reset_query(); ?>
		</div>
		</div>

		<div class="fivecol-two">
		<div class="div-content omega">
<?php		$args = array('posts_per_page' => $swift_options['np_slider_adjacent_posts_number'], 'no_found_rows' => true,'ignore_sticky_posts' => true, 'post_status' => 'publish');
			if( $swift_options['np_slider_adjacent_cats'] == -1){
				$args['orderby'] = 'rand';
			}elseif($swift_options['np_slider_adjacent_cats'] != -2){
				$args['cat'] = $swift_options['np_slider_adjacent_cats'];
			}
		
			$r = new WP_Query($args);
			if ($r->have_posts()) :
?>
			<p class="np-popular np-section-title"><?php echo $swift_options['np_adjacent_slider_title']?></p>
	
			<ul id="recent-posts">
<?php 			while ($r->have_posts()) : $r->the_post(); ?>
				<li>
					<h4 class="post-title"><a href="<?php the_permalink() ?>" title="<?php the_title() ?>"><?php the_title() ?></a></h4>	
					<?php  the_post_thumbnail( array(60,37), array('class' => 'alignleft np-recent' )); echo substr(get_the_excerpt(),0,160);?>
					<div class="clear"></div>
				</li>
<?php			endwhile; ?>
			</ul>
<?php 		endif;?>
<?php 		wp_reset_query(); ?>			
		</div>
		</div>

<?php 
		if( isset( $swift_options['np_above_tabbed_posts_ad_enable'] ) && $swift_options['np_above_tabbed_posts_ad_enable'] && isset( $swift_options['np_above_tabbed_posts_ad'] ) && $swift_options['np_above_tabbed_posts_ad'] != ''):
?>		
		<div style="margin:10px">	
		<?php 	echo stripslashes( $swift_options['np_above_tabbed_posts_ad'] )?>	
		</div>
<?php endif;?>			
	</div>	
	</div>
	<div class="clear"></div>

	<div id="tabbed-cats" class="div-content">
<?php 
		get_template_part( 'lib/includes/np-tabbed-cats');
?>
	</div>
		
	<div class="fourcol-three">
	<div class="div-content">
<?php 
		get_template_part( 'lib/includes/np-mag-boxes');
?>
	</div>
	</div>

	<div class="fourcol-one">
	<div class="div-content alignright">
		<?php dynamic_sidebar( 'np-sb' ); ?>		
	</div>
	</div>

</div><!-- #content -->
	
	</div><!-- left -->
	</div><!-- main -->
<?php //get_sidebar(); ?>
<?php get_footer(); ?>