<?php
get_header();

global $wpdb;
$wpdb->collection = $wpdb->prefix.'collection';
$user_id        = get_the_author_ID();
$all_collections = $wpdb->get_results( $wpdb->prepare("select post_id from $wpdb->collection where user_id = %d LIMIT 0,10", $user_id ) );

if( $all_collections ){
	foreach ($all_collections as $key => $value) {
		$collections_posts[] = $value->post_id;
	}

	$args = array(
		'post_type' => 'post',
		'post__in' => $collections_posts,
		'ignore_sticky_posts' => 1,
	);
	$collection_posts = new WP_Query($args);
}

?>
<section class="author ceo-background-default ceo-position-relative">
	<div class="author-head ceo-inline ceo-width-1-1 ceo-overflow-hidden">
	    <img src="<?php echo _ceo('user_default_thum'); ?>">
		<!--<img src="<//?php echo get_user_meta( $user_id , 'userbg' , true ); ?>">-->
		<div class="ceo-overlay ceo-position-top ceo-padding-large ceo-light">
			<div class="ceo-container">
				<div class="ceo-grid-small" ceo-grid>
					<div class="ceo-width-auto">
						<div class="avatar ceo-display-inline-block">
							<?php echo get_avatar( get_the_author_meta( 'ID' ),'100' ); ?>
						</div>
					</div>
					<div class="ceo-width-expand">
						<div class="author-head-info">
							<h1 class="ceo-h3"><?php the_author_nickname(); ?></h1>
							<p><?php echo the_author_meta( 'description'); ?></p>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</section>
<div class=" ceo-margin-medium-bottom">
	<ul class="ceo-user-y author-menu ceo-background-default ceo-text-center" ceo-switcher>
		<li class="ceo-display-inline-block"><a href="#" class="ceo-display-block ceo-position-relative ceo-padding-small ceo-padding-remove-horizontal">发布</a></li>
		<li class="ceo-display-inline-block"><a href="#" class="ceo-display-block ceo-position-relative ceo-padding-small ceo-padding-remove-horizontal">收藏</a></li>
	</ul>
	<div class="ceo-switcher ceo-margin-medium-top">
		<div class="ceo-container">
			<div class="ceo-animation-slide-left-small" ceo-grid>
				<?php
                //我的发布
                global $wp_query;
                $page=!empty(get_query_var('paged')) ?get_query_var('paged') :1;
                $wp_query = new WP_Query(
                    array(
                        'post_type'      => 'post',
                        'posts_per_page' => 12,
                        'post_status'    => 'publish',
                        'author' => $user_id,
                        'paged' => $page

                    )
                );

                if(have_posts()) : while (have_posts()) : the_post(); ?>

				<div class="ajax-item ceo-width-1-1@s ceo-width-1-4@xl">
					<?php get_template_part( 'template-parts/home/loop', 'card' ); ?>

				</div>
				<?php endwhile; else: ?>
				<div class="ceo-width-1-1">
					<div class="ceo-alert-primary ceo-width-1-2 ceo-container" ceo-alert>
						<a class="ceo-alert-close" ceo-close></a>
						<p class="ceo-padding-small ceo-text-center">很懒，很个性，就不发动态！！</p>
					</div>
				</div>
				<?php endif;
                wp_reset_query();
                ?>
			</div>
            <div class="fenye ceo-text-center ceo-text-small ceo-margin-large-top ceo-margin-large-bottom">
                <?php fenye(); ?>
            </div>
		</div>
		<div class="ceo-container">
			<div class="ceo-animation-slide-left-small" ceo-grid>
				<?php
				if( $collection_posts && $collection_posts->have_posts() ){
					while( $collection_posts->have_posts() ) : $collection_posts->the_post();
				?>

				<div class="ajax-item ceo-width-1-1@s ceo-width-1-4@xl">
					<?php get_template_part( 'template-parts/home/loop', 'card' ); ?>

				</div>
				<?php endwhile; ?>
				<?php }else{ ?>
				<p>暂无收藏</p>

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