<?php
/**
 * Template Name: Grid Portfolio Template
 * 
 * @package WordPress
 * @subpackage Probit
 * @since Probit 1.0
 *
 */
if (!defined('ABSPATH')) {
    exit; // Exit if accessed directly
}
get_header();
?>

<div class="single_top_bar entry-header">
    <div class="container">
        <div class="row">
            <h1 class="entry-title text-capitalize col-xs-12"><?php the_title(); ?></h1>
            <?php if (get_theme_mod('enable_breadcrumbs')) { ?>
                <div class="col-xs-12"><?php probit_breadcrumb(); ?></div>
            <?php } ?>
        </div>
    </div>
</div>
<div class="container">
    <div class="row">
        <div id="primary" class="col-xs-12">
            <div id="content" role="main">
                <?php
                // Call edit portfolio link when admin loggedin
                edit_post_link(__('Edit', 'probit'), '<span><i class="fa fa-pencil-square-o"></i> ', '</span>');
                ?>
                <div class="col-md-12 col-xs-12 col-sm-12 padding_0">
                    <?php
                    global $wp_query, $post;
                    $post_id_page = $post->ID;
                    $port_cat = esc_attr(get_theme_mod('port_cat'));
                    if ($port_cat != 0) {
                        $cat_display_array = probit_get_subcat_ids($port_cat);
                        $args = array('post_type' => 'post', 'post_status' => 'publish', 'order' => 'DESC', 'posts_per_page' => -1, 'category__in' => $cat_display_array);
                        $loop = new WP_Query($args);
                        if ($loop->have_posts()) {
                            while ($loop->have_posts()) : $loop->the_post();
                                $terms = wp_get_post_terms(get_the_ID(), 'category');
                                $termslug = '';
                                foreach ($terms as $term) {
                                    $termslug .= $term->slug . ' ';
                                }
                                ?>
                                <div class="col-md-3 col-sm-4 col-xs-12 portfolio_contain">
                                    <div class="portfolio_wrapper">
                                        <?php
                                        if (has_post_thumbnail())
                                            the_post_thumbnail('probit-portfolio-slider-img');
                                        else
                                            echo '<img alt="' . esc_attr(get_the_title()) . '" src="' . esc_url(get_template_directory_uri() . '/images/no_image_370.png') . '" />';
                                        ?>
                                        <div class="overlay"></div>
                                        <div class="portfolio_item_content">
                                            <h3><a href='<?php the_permalink(); ?>' class="text-capitalize"><?php the_title(); ?></a></h3>
                                            <p>
                                                <?php
                                                $separtor = ' ';
                                                // get lists of term associated in the current post type
                                                $terms = get_the_terms(get_the_ID(), 'category');
                                                if ($terms) {
                                                    foreach ($terms as $term) {
                                                        // get term link, the function name explain it
                                                        $term_link = get_term_link($term, 'category');

                                                        // the function explain its purpose
                                                        if (is_wp_error($term_link))
                                                            continue;

                                                        // display term name with link
                                                        echo $separtor . '<span>' . $term->name . '</span>';
                                                        $separtor = '<span> , </span>';
                                                    }
                                                }
                                                ?>
                                            </p>
                                        </div>
                                    </div>
                                </div>
                                <?php
                            endwhile;
                        }
                        wp_reset_postdata();
                    }
                    ?>
                </div>

            </div><!-- #content -->
        </div><!-- #primary -->
    </div><!-- .row -->
</div><!-- .container -->

<?php get_footer(); ?>