<?php 
/*
	template name: 我的收藏
	description: template for mobantu.com Monkey theme 
*/
if(!is_user_logged_in()){
	echo "<script>window.location.href='".get_permalink(get_page_id_from_template('page-login.php'))."';</script>";
}else{
get_header();
global $wpdb;
?>
<link rel="stylesheet" href="<?php bloginfo("template_url")?>/static/css/user.css">
<div class="content main-content-wrap ng-scope">
  <div class="user-center-wrapper ng-scope">
    <div class="container">
      <div class="row">
        <?php include('modules/pageUserSide.php');?>
        <div class="col-xs-10 col-sm-10 col-md-10 col-lg-10">
          <div class="favorite-wrapper ng-scope">
            <?php 
				$counts = $wpdb->get_var("SELECT count(*) FROM ".$wpdb->prefix."collect WHERE user_id=".get_current_user_id());
				$perpage = 10;
				$pages = ceil($counts / $perpage);
				$paged = (get_query_var('paged')) ? $wpdb->escape(get_query_var('paged')) : 1;
				$offset = $perpage*($paged-1);
				$lists = $wpdb->get_results("SELECT * FROM ".$wpdb->prefix."collect where user_id=".get_current_user_id()." order by id desc limit $offset,$perpage");
				$DisplaysID = '';
			?>
            <ul class="nav nav-tabs" role="tablist">
              <li class="active"><a>我的收藏<span class="badge ng-binding ng-scope"><?php echo $counts;?></span></a></li>
            </ul>
            <div class="ng-isolate-scope loading-content-wrap loading-show loading-show-active">
              <?php
              	if($lists) {
			  ?>
              <div class="list-group ng-scope">
                <div class="list-group-item content-list-item ng-scope">
                  <?php foreach($lists as $value){ ?>
                  <section class="news-item"> <a class="pic" target="_blank" href="<?php echo get_permalink($value->post_id);?>"> <img alt="<?php echo get_post($value->post_id)->post_title;?>" src="<?php echo MThemes_thumbnail_custom(95,63,$value->post_id)?>"> </a>
                    <div class="actions"> <span class="time ng-binding"><?php echo $value->create_time?> 收藏</span> <a class="del" onclick="wpcollect2(<?php echo $value->post_id;?>, <?php echo get_current_user_id();?>)" href="javascript:void(0)" >删除</a> </div>
                    <div class="desc"> <a class="title ng-binding" target="_blank" href="<?php echo get_permalink($value->post_id);?>"><?php echo get_post($value->post_id)->post_title;?></a> <span class="brief ng-binding"><?php echo mb_strimwidth( mbthemes_strip_tags( get_post($value->post_id)->post_content ), 0, 50,"...");?></span> </div>
                  </section>
                  <?php }?>
                </div>
              </div>
              <div class="text-center">
                <nav class="text-center comp-pagination">
                  <?php MBT_monkey_page_pagination($paged,$pages);?>
                </nav>
              </div>
			  <?php }?>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>
</div>
</div>
<?php get_footer();}?>
