<?php get_header(); ?>
<?php global $qaleb;?>
<div class="gallery-content">
<div class="container">
<div class="wrapper">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php setPostViews(get_the_ID());?>
<?php
add_filter('post_gallery', 'my_post_gallery', 10, 2);
function my_post_gallery($output, $attr) {
global $post;

if (isset($attr['orderby'])) {
$attr['orderby'] = sanitize_sql_orderby($attr['orderby']);
if (!$attr['orderby'])
unset($attr['orderby']);
}

extract(shortcode_atts(array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post->ID,
'itemtag' => 'dl',
'icontag' => 'dt',
'captiontag' => 'dd',
'size' => 'thumbnail',
'include' => '',
'exclude' => ''
), $attr));

$id = intval($id);
if ('RAND' == $order) $orderby = 'none';

if (!empty($include)) {
$include = preg_replace('/[^0-9,]+/', '', $include);
$_attachments = get_posts(array('include' => $include, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby));

$attachments = array();
foreach ($_attachments as $key => $val) {
$attachments[$val->ID] = $_attachments[$key];
}
}

if (empty($attachments)) return '';

$output = "<div class=\"lightgallery gallery\">\n";

foreach ($attachments as $id => $attachment) {

$img = wp_get_attachment_image_src($id, 'full');

$output .= "<a href=\"{$img[0]}\" class=\"col-lg-4 col-md-6 col-sm-12\">\n";
$output .= "<img src=\"{$img[0]}\" width=\"{$img[1]}\" height=\"{$img[2]}\" alt=\"\" />\n";
$output .= "</a>\n";
}

$output .= "</div>\n";

return $output;
}
the_content(); ?>
<?php endwhile; else : endif; ?>
</div>
</div>
</div>


<?php if($qaleb['gallery-social-ac']=='1'){?>
<div class="sh-are">
<a href="https://www.linkedin.com/shareArticle?mini=true&amp;url=<?php the_permalink() ?>"><div class="icon lin-sh"><i class="fa fa-linkedin"></i></div></a>
<a href="http://www.facebook.com/sharer/sharer.php?u=<?php the_permalink(); ?>"><div class="icon dblue"><i class="fa fa-facebook"></i></div></a>
<a href="http://twitter.com/home?status=<?php the_permalink(); ?>"><div class="icon blue"><i class="fa fa-twitter"></i></div></a>
<a href="https://telegram.me/share/url?url=<?php the_permalink(); ?>"><div class="icon blue"><i class="fa fa-send-o"></i></div></a>
<a href="https://wa.me/?text=<?php the_permalink(); ?>"><div class="icon what-sh"><i class="fa fa-whatsapp"></i></div></a>
</div>
<?php } ?>

<div class="post-ga">
<div class="container">
<div class="wrapper">
<ul>
<?php if($qaleb['gallery-cod-ac']=='1'){?><li><i class="fa fa-file-text-o"></i> کد خبر : <?php the_ID();?></li><?php } ?>
<?php if($qaleb['gallery-date-ac']=='1'){?><li><i class="fa fa-calendar"></i> <?php the_date('');  ?> - <?php the_time('');  ?></li><?php } ?>		
<?php if(get_post_meta( get_the_ID(), 'meta-text-6', true )!=null){ ?><li><i class="fa fa-camera" aria-hidden="true"></i> عکاس : <?php echo get_post_meta( get_the_ID(), 'meta-text-6', true ); ?> </li><?php } ?>
<?php if($qaleb['gallery-user-ac']=='1'){?><li><i class="fa fa-user" aria-hidden="true"></i> ارسال : <?php the_author_posts_link(); ?></li><?php } ?>
<?php if($qaleb['gallery-view-ac']=='1'){?><li><i class="fa fa-eye" aria-hidden="true"></i> بازدید : <?php echo getPostViews (get_the_ID()); ?></li><?php } ?>
<?php if($qaleb['gallery-comments-ac']=='1'){?><li><i class="fa fa-commenting-o" aria-hidden="true"></i>  <?php comments_popup_link('بدون دیدگاه', 'يک دیدگاه', '% دیدگاه'); ?></li><?php } ?>
<?php if($qaleb['gallery-link-ac']=='1'){?><li><i class="fa fa-link"></i><?php echo wp_get_shortlink(); ?></li><?php } ?>
</ul>
</div>
</div>
</div>

<div class="container">
<div class="wrapper">
<?php if($qaleb['gallery-ac']=='1'){?>
<div class="ap-page">
<div class="ttit">
<h3><?php echo $qaleb['relate-gallery-title']; ?></h3>
</div>
<div class="postlist">
<?php
$categories = get_the_category();
$cats = array();
foreach ( $categories as $category ) { 
$cats[] = esc_attr( $category->term_id ); 
}
$args = new WP_Query(array(
'post_type' =>'gallery',
'cat'	=> $cats,
'posts_per_page' => $qaleb['gallery-related-count'],
'post__not_in' => array(get_the_ID()),
));
if($args->have_posts()) : while($args->have_posts()) : $args->the_post();
?>
<div class="item">
<div class="thumbnail">
<?php if(has_post_thumbnail()){?>
<a href="<?php the_permalink(); ?>"><img src="<?php the_post_thumbnail_url('loop-2'); ?>" alt="<?php the_title(); ?>"></a>
<?php }else{ ?>
<img src="<?php bloginfo("template_url"); ?>/img/none.png">
<?php } ?>				
 </div>
		 <div class="det">
            <div class="play"><i class="fa fa-camera"></i></div>
            <p><?php the_title(); ?></p>
            <time><span><?php the_time(' d F Y ');  ?></b></span></time>
          </div>
           <a class="plink" href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"></a> 
        </div>         
<?php endwhile; endif;  wp_reset_query(); ?>
 </div>
</div>
<?php } ?>

<div id="comments" class="comments-area">
<div class="ttit"><h3>ارسال دیدگاه</h3>
<?php if($qaleb['comments-1'] == '1'){?><b><?php $comments_count = wp_count_comments(get_the_ID()); echo "مجموع دیدگاهها : " . $comments_count->total_comments; ?></b><?php } ?>
<?php if($qaleb['comments-2'] == '1'){?><b><?php $comments_count = wp_count_comments(get_the_ID()); echo "در انتظار بررسی : " . $comments_count->moderated; ?></b><?php } ?>
<?php if($qaleb['comments-3'] == '1'){?><b>انتشار یافته : <?php comments_number('0', '1', '%' );?></b><?php } ?>
</div>
<?php comments_template(); ?>
</div>
</div>
</div>

<style>input[type=email]:not(.browser-default){width:94.5%;}.post-info{margin: 15px 0;}#comments{margin-top: 10px;}.ap_header{z-index:996;}</style>
<?php get_footer(); ?>
<script type="text/javascript">
$(document).ready(function() {
$(".lightgallery").lightGallery();
});
</script>