<?php /* Template Name: inicio_optimizado */ ?>
<?php
/**
 * The template for displaying all pages.
 *
 * This is the template that displays all pages by default.
 * Please note that this is the WordPress construct of pages
 * and that other 'pages' on your WordPress site will use a
 * different template.
 *
 * @package bloggr
 */

get_header(); ?>

<?php
global $wpdb;
global $post;

	$user_id = get_current_user_id();
//echo 'USER: '. $user_id.'--';	
		$user_categories = get_user_categories_3($user_id);
	
			$date= date('Y-m-d', strtotime('-30 days'));
		
			 if (sizeof($user_categories)>0){
				//echo 'CATS:'. sizeof(user_categories);
			 	$str_categorias =implode(",",$user_categories);
			 	$query1=get_query_noticias();
			 	$query1= str_replace  ('#categorias_usuario#',$str_categorias,$query1);
			 	$where1='1=1 ';
			 	/*if (is_tag()){
			 		$where1='etiqueta_term.name=\''.$concepto->name.'\'';
			 	}else if(is_category()){
			 		$where1='categoria_term.name=\''.$concepto->name.'\'';
			 	}else if(is_tax() && $taxonomia->name=='fuente'){
			 		$where1='fuente_term.name=\''.$concepto->name.'\'';
			 	}*/
			 	$query1= str_replace  ('#condiciones_adicionales#',$where1,$query1);
				$pageposts = $wpdb->get_results($wpdb->prepare( $query1,$date,$user_id));
			 	
				
					
	
			 }
?>

<div class="grid grid-pad">
<?php get_sidebar(); ?>
	<div class="col-8-12">
        <div id="primary" class="content-area">
            <main id="main" class="site-main" role="main">
    
                 <?php if ($pageposts): ?>
  <?php global $post;

  ?>
  <?php foreach ($pageposts as $post):
    
                     get_template_part( 'content_optimizado', '' ); ?>
    
                    <?php
                        // If comments are open or we have at least one comment, load up the comment template
                       /* if ( comments_open() || get_comments_number() ) :
                            comments_template();
                        endif;*/
                    ?>
    
                              
  <?php endforeach; ?>
  <?php else : ?>
    <h2 class="center">No se han encontrado entradas de su interés en los últimos 3 meses</h2>

    <?php include (TEMPLATEPATH . "/searchform.php"); ?>
 <?php endif; ?>
    
            </main><!-- #main -->
        </div><!-- #primary -->
	</div>

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