<?php
$author_id = intval(get_query_var('author'));
$current = (intval(get_query_var('paged'))) ? intval(get_query_var('paged')) : 1;
$instance['paged'] = $current;
$instance['author'] =  $author_id;
$instance['posts_per_page'] =  get_option('posts_per_page', 10);
$instance['orderby'] = 'date';

$arg = kopa_build_query($instance);
$authors = new WP_Query($arg );
if( $authors->have_posts() ){
	?>
	<ul class="clearfix">
		<?php while( $authors->have_posts() ){
            $authors->the_post();
			$post_excerpt = kopa_get_the_excerpt_for_widget(get_the_excerpt(), get_the_content(), get_theme_mod('blog_excerpt', 55));
            $featured_content = get_post_meta(get_the_ID(),'single_post_featured_content',true);
            $post_format = get_post_format();
            $classes = array('entry-item');
            if(is_sticky( get_the_ID() )){
                array_push( $classes, 'sticky-post');
            }

			?>
			<li>
                <?php if('quote' == $post_format ){
                    $post_content = get_the_content();
                    if ( !empty($post_content) ) {
                        the_content();
                    } else {
                        echo '<blockquote><p>'. esc_html(get_the_title()) .'</p></blockquote>';
                    }
                ?>

                <?php } else{?>

                    <article <?php post_class($classes); ?>>
                    <?php
                    if(is_sticky( get_the_ID() )){
                        ?>
                        <span class="sticky-icon"></span>
                        <?php
                    }
                    ?>
                    <?php if( ! is_search() ){ ?>
                    <div class="entry-thumb">

                    <?php get_template_part( 'library/templates/post-featured-content/content' ); ?>

                    </div>
                    <?php } ?>

                    <?php if( get_theme_mod('blog_date_status', 1) || get_theme_mod('blog_comment_status', 1) || get_theme_mod('blog_category_name_status', 1)){ ?>
                    <div class="entry-meta">
                        <?php if(get_theme_mod('blog_date_status', 1)){ ?>
                        <span class="entry-date"><a href="<?php the_permalink(); ?>"><?php echo get_the_date('F j,Y'); ?></a></span>
                        <?php } ?>
                        <?php if(get_theme_mod('blog_comment_status', 1)){ ?>
                        <?php if(comments_open() && !post_password_required()){ ?>
                            <span class="entry-comment"> / <?php comments_popup_link('No comment', '1 comment', '% comments'); ?></span>
                            <?php } ?>
                        <?php } ?>
                        <?php
                        $post_categories = wp_get_post_categories( get_the_ID() );
                        if( get_theme_mod('blog_category_name_status', 1) && $post_categories ){ ?>
                        <span class="entry-categories"> / <?php echo esc_html__('in:','garajez-lite'); ?> <?php the_category(', '); ?></span>
                        <?php } ?>
                    </div>
                    <?php } ?>
                    <?php if(get_theme_mod('blog_title_status', 1)){ ?>
                    <h3 class="entry-title" itemscope="" itemtype="http://schema.org/Event"><a itemprop="name" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h3>
                    <?php } ?>
                    <?php if(get_theme_mod('blog_excerpt_status', 1)){ ?>
                    <?php if(!empty($post_excerpt)){ ?>
                        <p><?php echo esc_html($post_excerpt); ?></p>
                        <?php } ?>
                    <?php } ?>
                    <?php if(get_theme_mod('blog_readmore_status', 1)){ ?>
                    <a href="<?php the_permalink(); ?>" class="more-link"><?php echo esc_html__('Read more','garajez-lite'); ?></a>
                    <?php } ?>
                </article>

                <?php } ?>
            </li>

			<?php
		} ?>
	</ul>
	<?php
        #PAGINATION
        global $wp_rewrite;
        $total = $authors->max_num_pages;
        if ($total > 1) {
            $current = (get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
            $pagination_args = array(
                'base' => @add_query_arg('paged', '%#%'),
                'format' => '',
                'current' => $current,
                'total' => $total,
                'end_size' => 2,
                'mid_size' => 1,
                'type' => 'list',
                'prev_next' => TRUE,
                'prev_text' => esc_attr__('Previous','garajez-lite'),
                'next_text' => esc_attr__('Next','garajez-lite')
            );

            if ($wp_rewrite->using_permalinks())
                $pagination_args['base'] = user_trailingslashit(trailingslashit(remove_query_arg('s', get_pagenum_link(1))) . 'page/%#%/', 'paged');

            if (!empty($authors->query_vars['s']))
                $pagination_args['add_args'] = array('s' => urlencode(get_query_var('s')));

            echo '<div class="kopa-pagination">';
            echo paginate_links($pagination_args);
            echo '</div>';
        }

        wp_reset_postdata();
} else {
    ?>
        <h2 class="entry-title"><?php echo esc_html__('Nothing Found...', 'garajez-lite'); ?></h2>
<?php }


