<?php get_header(); ?>
<?php setPostViews($post->ID); if (get_theme_mod( 'charsoogh_single_blog_layout' ) == 'sidebar_none'){$blog_layout = 'col-md-12';}else{$blog_layout = 'col-md-8';} ?>
<main class="content">
            <section class="block">
                <div class="container">
                    <div class="row">
<?php if (get_theme_mod( 'charsoogh_single_blog_layout' ) == 'sidebar_right' || empty(get_theme_mod( 'charsoogh_single_blog_layout' ))){ get_sidebar(); } ?>
                        <div class="<?php echo $blog_layout; ?>">
                          <?php if(have_posts()):?>
                            <?php while(have_posts()) :the_post();?>
                            <article class="blog-post clearfix">
                              <?php if (get_theme_mod( 'charsoogh_blog_thumb_show' ) != 'no') : ?>
                                <div class="post_thumb overlayer">
                                  <?php if(has_post_thumbnail()){
                                    the_post_thumbnail();
                                    echo '<h2>' . get_the_title() . '</h2>';
                                  } ?>
                                </div>
                              <?php endif; ?>
                                <div class="blog-post-content">
                                  <?php the_content(); ?>

                                  <?php
                                  if (get_theme_mod( 'charsoogh_blog_share_show') != 'no') :
                                  // Get current page URL
                                  $crunchifyURL = urlencode(get_permalink());
                                  // Get current page title
                                  $crunchifyTitle = str_replace( ' ', '%20', get_the_title());
                                  // Get Post Thumbnail for pinterest
                                  $crunchifyThumbnail = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'full' );
                                  // Construct sharing URL without using any script
                                  $twitterURL = 'https://twitter.com/intent/tweet?text='.$crunchifyTitle.'&amp;url='.$crunchifyURL.'&amp;via=Crunchify';
                                  $facebookURL = 'https://www.facebook.com/sharer/sharer.php?u='.$crunchifyURL;
                                  $whatsappURL = 'whatsapp://send?text='.$crunchifyTitle . ' ' . $crunchifyURL;
                                  ?>
                                  <div class="crunchify-social">
                                  <span>
                                    <i class="fa fa-share-alt" aria-hidden="true"></i> <?php _e('Share' ,'charsoogh'); ?>
                                  </span>
                                  <a class="crunchify-link crunchify-telegram" target="_blank" onclick="teleShare();"><i class="fa fa-telegram"></i></a>
                                  <a class="crunchify-link crunchify-facebook" href="<?php echo $facebookURL; ?>" target="_blank"><i class="fa fa-facebook-f"></i></a>
                                  <a class="crunchify-link crunchify-whatsapp" href="<?php echo $whatsappURL; ?>" target="_blank"><i class="fa fa-whatsapp"></i></a>
                                  <a class="crunchify-link crunchify-twitter" href="<?php echo $twitterURL; ?>" target="_blank"><i class="fa fa-twitter"></i></a>
                                  <script>
                                  function teleShare() {
                                  var r = confirm("<?php _e('Would you like to share in the telegram?' ,'charsoogh'); ?>");
                                  if (r == true) {
                                  window.location.replace('https://telegram.me/share/url?text=&url='+window.location.href);
                                  }
                                  }
                                  </script>
                                  </div>
                                  <?php endif; ?>
                                <?php
                                if (get_theme_mod( 'charsoogh_blog_tags_show') != 'no') :
                                $tags = get_the_tags(get_the_ID());
                                if(has_tag()) :
                                 ?>
                                  <div class="tags framed">
                                    <span><i class="fa fa-tags" aria-hidden="true"></i> <?php _e('Tags:' ,'charsoogh'); ?> </span>
                                <?php
                                  foreach($tags as $tag){
                                    echo '<a href="'.get_tag_link($tag->term_id).'" rel="tag" class="tag">'.$tag->name.'</a>';
                                }
                                ?>
                                </div>
                                <?Php endif; ?>
                                <?php endif; ?>
                                <?php if (get_theme_mod( 'charsoogh_blog_next_prev_show') != 'no') : ?>
                                <section class="bottom-post">
                                    <div class="blog-posts-navigation clearfix">
                                          <?php previous_post_link( '<div class="prev"><i class="fa fa-chevron-left"></i><figure>'. __('Previous Post' , 'charsoogh') .'</figure><h3> %link </h3></div>', '%title', true ); ?>
                                          <?php next_post_link( '<div class="next"><i class="fa fa-chevron-right"></i><figure>'. __('Next Post' , 'charsoogh') .'</figure><h3> %link </h3></div>', '%title', true ); ?>
                                    </div>
                                    <!--end blog-posts-navigation-->
                                </section>
                                <?php endif; ?>
                                </div>
                            </article>
                            <?php endwhile; endif; ?>

              <?php if (get_theme_mod( 'charsoogh_blog_related_show') != 'no') : ?>
              <section class="index-blog blog-block">
                  <div class="container">
                    <div class="section-title clearfix">
                    <h2><?php _e('Related Posts' , 'charsoogh'); ?></h2>
                    </div>

                    <div class="row blog-carousel owl-carousel">
                      <?php
                     $related = get_posts( array( 'category__in' => wp_get_post_categories($post->ID), 'numberposts' => 6, 'post__not_in' => array($post->ID) ) );
                      if( $related ) foreach( $related as $post ) {
                      setup_postdata($post);
                      ?>
                      <div class="blog-item">
                        <div class="images">
                          <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                          <?php if(has_post_thumbnail()){the_post_thumbnail('img-260-200');}else{ ?>
                          <img src="<?php bloginfo('template_directory'); ?>/assets/img/featured-image-missing.png" alt="<?php _e('No image available' , 'charsoogh'); ?>">
                        <?php } ?>
                          </a>
                        <p class="blog-detail">
                          <span>
                            <?php if (empty(get_theme_mod( 'charsoogh_blog_date_type')) || get_theme_mod( 'charsoogh_blog_date_type') == 'advanced') : ?>
                            <i class="fa fa-calendar-o"></i> <?php echo human_time_diff( get_the_time('U'), current_time('timestamp') ) . __(' Ago' , 'charsoogh'); ?>
                            <?php else: ?>
                            <i class="fa fa-calendar-o"></i> <?php echo get_the_date(); ?>
                            <?php endif; ?>
                          </span>
                          <span>
                            <i class="fa fa-bookmark-o"></i>
                            <?php
                            $category_array = wp_get_post_categories($post->ID);
                            $category_list = array();
                            foreach ( $category_array as $categories ) {
                                $category_list[] = get_cat_name( $categories );
                            }
                            $lister = implode(' / ', $category_list);
                            $list_categories = $lister;
                            echo $lister ;
                        ?>
                          </span>
                          <?php if (get_theme_mod( 'charsoogh_visit_blog_show') != 'no') : ?>
                          <span><i class="fa fa-pie-chart" aria-hidden="true"></i> <?php echo getPostViews(get_the_ID()); ?></span>
                          <?php endif; ?>
                        </p>
                        </div>
                        <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>">
                          <h3><?php the_title(); ?></h3>
                        </a>
                        <div class="blog-meta">
                          <?php echo excerpt(17); ?>
                        </div>
                      </div>
                    <?php } ?>
                    </div>
              <?php if (get_theme_mod( 'charsoogh_blog_layout' )) : $blog_layout = get_theme_mod( 'charsoogh_blog_layout'); else: $blog_layout = '4'; endif; ?>
              <script>
              jQuery(document).ready(function($) {jQuery(".blog-carousel").owlCarousel({loop:!1,margin:20,nav:!0,dots:!1,items:3,<?php if(is_rtl()): echo 'rtl:!0'; else: echo 'ltr:!0'; endif; ?>,navText:["<i class='fa fa-chevron-left'></i>","<i class='fa fa-chevron-right'></i>"],URLhashListener:!0,responsive:{768:{items:3},0:{items:1,center:!1,margin:0,autoWidth:!1}}});});
              </script>
                  </div>
              </section>
              <?php endif; ?>

                            <?php comments_template(); ?>

                        </div>
                        <!--end col-md-8-->
<?php if (get_theme_mod( 'charsoogh_single_blog_layout' ) == 'sidebar_left'){ get_sidebar(); } ?>
                    </div>
                </div>
                <!--end container-->
            </section>
            <!--end block-->
        </main>

<?php get_footer(); ?>
