<div class="content widt-sidbar_3 widt-sidbar_5 main-content" style="margin-top:1rem;">
    <div class="container">
        <div class="row">
            <div class="col-12 col-md-6 sidebar">
                <?php 
                if ($settings['list']):
                foreach ($settings['list'] as $item):
                     if (!empty($item['grid_pagination'])) {
                         $paged         = get_query_var('paged');
                         if (empty($paged)) {
                             $paged         = get_query_var('page');
                         }
                         $args['paged'] = $paged;
                     }
                     if (empty($item['title']) && empty($item['description']) && empty($item['button']) && 'none' == $item) {
                         $print_content = false;
                     }
             
                     $posts_per_page = (!empty($item['posts_per_page']) ?  $item['posts_per_page'] : 3);
                     $cats = is_array($item['post_categories']) ? implode(',', $item['post_categories']) : $item['post_categories'];
                     $query_args = array(
                         'posts_per_page'     => absint($posts_per_page),
                         'no_found_rows'      => true,
                         'post__not_in'          => get_option('sticky_posts'),
                         'ignore_sticky_posts'   => true,
                         'category_name'     => $cats
                     );
                     // Order by.
                     if (!empty($item['orderby'])) {
                         $query_args['orderby'] = $item['orderby'];
                     }
                     // Order .
                     if (!empty($item['order'])) {
                         $query_args['order'] = $item['order'];
                     }
                     $all_posts = new \WP_Query($query_args);
             
                     if ($all_posts->have_posts()) : 
                     if ($item['bg_image']['id']): ?>
                <div class="adlist_them">
                    <div class="row">
                        <div class="col-12 col-sm-6">
                            <a href="<?php echo $item['bg_image_link']['url']; ?>" target="_blank">
                                <?php echo wp_get_attachment_image( $item['bg_image']['id'], 'thumbnail' ); ?>
                            </a>
                        </div>
                        <div class="col-12 col-sm-6">
                            <a href="<?php echo $item['image_link']['url']; ?>" target="_blank">
                                <?php echo wp_get_attachment_image( $item['image']['id'], 'thumbnail' ); ?>
                            </a>
                        </div>
                    </div>
                </div>
                <?php endif; ?>
                <div class="hed_title_arch"><?php echo $item['list_title']; ?></div>
                <div class="contentlist_arch">
                    <div class="row">
                        <?php $all_posts->the_post(); ?>
                        <div class="col-12">
                            <div class="cardSuggestions">
                                <a href="<?php the_permalink(); ?>" class="card__picture">
                                    <?php the_post_thumbnail('articlethumb'); ?>
                                </a>
                                <div class="card__overload">
                                    <a href="<?php the_permalink(); ?>" class="card__overload--link"></a>
                                    <a href="<?php the_permalink(); ?>" class="card__overload--title">
                                        <?php the_title(); ?>
                                    </a>
                                    <div class="card__overload--info">
                                        <div class="card__overload--author">
                                            نوشته شده توسط <?php the_author(); ?>
                                        </div>
                                        <div class="card__overload--date">
                                            <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' پیش'; ?>
                                        </div>
                                    </div>
                                </div>
                                <span href="#" class="card__bookmark"></span>
                            </div>
                        </div>
                        <?php 
                    while ($all_posts->have_posts()) :
                        $all_posts->the_post();
                        ?>
                        <div class="col-12 col-sm-6">
                            <div class="cardSuggestions">
                                <a href="<?php the_permalink(); ?>" class="card__picture">
                                    <?php the_post_thumbnail('articlethumb'); ?>
                                </a>
                                <div class="card__overload">
                                    <a href="<?php the_permalink(); ?>" class="card__overload--link"></a>
                                    <a href="<?php the_permalink(); ?>" class="card__overload--title">
                                        <?php the_title(); ?>
                                    </a>
                                    <div class="card__overload--info">
                                        <div class="card__overload--author">
                                            نوشته شده توسط <?php the_author(); ?>
                                        </div>
                                        <div class="card__overload--date">
                                            <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . ' پیش'; ?>
                                        </div>
                                    </div>
                                </div>
                                <span href="#" class="card__bookmark"></span>
                            </div>
                        </div>
                        <?php 
                        endwhile;
                        wp_reset_postdata(); ?>
                    </div>
                </div>
                <?php endif; endforeach; endif; ?>
            </div>
            <div class="col-12 col-md-6 content content-fix">
                <section class="artic_list_arch">
                <div class="title-category-header post-content">
                    <h1 class="cb-module-title"><?php echo $settings['title']; ?></h1>
                    <div class="taxonomy-description"><?php echo $settings['title_more']; ?></div>
                </div>
                <?php
                    while ($query->have_posts()) :
                        $query->the_post(); ?>
                <article class=" main solid-home home-col">
                    <div class="row">
                        <div class="col-8 col-sm-8 col-xs-8">
                            <h3>
                                <a class="article_Title" href="<?php the_permalink(); ?>">
                                    <?php the_title(); ?>
                                </a>
                            </h3>
                            <div class="post-meta-area">
                                <?php
                                        $avatar_name  = ot_get_option('avatar_name', false);
                                        if ($avatar_name  == 'on') :
                                    ?>
                                <a class="cursor-meta" href="<?php the_permalink(); ?>"><?php the_author(); ?></a>
                                <?php endif; ?>
                                <a class="cms-post-recent" href=""><i class="fa fa-comments-o" aria-hidden="true"></i>
                                    <?php comments_number('0', '1', '%'); ?></a>
                                <span><?php do_action('type_article'); echo human_time_diff(get_the_time('U'), current_time('timestamp')) . ' پیش'; ?></span>
                            </div>
                            <div class="excerpt_article">
                                <?php if ($settings !== 'yes') {
                                            if (empty($settings['grid_content_length'])) {
                                                the_excerpt();
                                            } else {
                                                echo wp_trim_words(get_the_excerpt(), $settings['grid_content_length']);
                                            }
                                        } ?>
                            </div>
                        </div>
                        <div class="col-4 col-sm-4 col-xs-4">
                            <a href="<?php the_permalink(); ?>">

                                <?php
                                        if (has_post_thumbnail()) {
                                            the_post_thumbnail('medium', array('alt' => '' . get_the_title(), 'title' => '' . get_the_title() . ''));
                                        } else { ?>
                                <img src="<?php bloginfo('template_url'); ?>/assets/images/thumb.gif" width="60"
                                    height="60" alt="<?php _e('Image not found', 'leora'); ?>"
                                    title="<?php _e('Image not found', 'leora'); ?>">
                                <?php } ?>
                            </a>
                        </div>
                    </div>
                </article>
                <?php endwhile;
                    // Pagination.
                    if (!empty($settings['grid_pagination'])) {
                    ?>
                <div class="pagination">
                    <?php
                            $big = 999999999;
                            $totalpages = $query->max_num_pages;
                            $current = max(1, $paged);
                            $paginate_args = array(
                                'base'      => str_replace($big, '%#%', esc_url(get_pagenum_link($big))),
                                'format'    => '?paged=%#%',
                                'current'   => $current,
                                'total'     => $totalpages,
                                'show_all'  => false,
                                'end_size'  => 1,
                                'mid_size'  => 1,
                                'prev_next' => true,
                                'prev_text'          => __('<i class="fa fa-chevron-right" aria-hidden="true"></i>', 'twentyfifteen'),
                                'next_text'          => __('<i class="fa fa-chevron-left" aria-hidden="true"></i>', 'twentyfifteen'),
                                'screen_reader_text' => __('A')
                            );

                            $pagination = paginate_links($paginate_args);
                            ?>
                    <nav class="pagenumbers">
                        <?php echo $pagination; ?>
                    </nav>
                    </section>
                </div>
                <?php
                    }
                    wp_reset_postdata();
                    ?>
            </div>
        </div>
    </div>
</div>