<?php
/**
 * Template Name: Isotope 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
                $port_cat = esc_attr(get_theme_mod('port_cat'));
                if ($port_cat != 0) {
                    ?>
                    <div class="row">
                        <div class="col-md-12">
                            <?php
                            // Call edit portfolio link when admin loggedin
                            edit_post_link(__('Edit', 'probit'), '<span><i class="fa fa-pencil-square-o"></i> ', '</span>');
                            $cat_display_array = array();
                            ?>
                            <div class="filter_portfolio">
                                <ul class="list-inline" id="category_menu_ul">
                                    <li id="category_menu_Showall" class="show_all">
                                        <a class="category_menu_selected" href="#"><?php _e('Show all', 'probit'); ?></a>
                                    </li>                                                
                                    <?php
                                    $cat_display_array = probit_get_subcat_ids($port_cat);
                                    $categories = get_categories(array('child_of' => $port_cat));
                                    if (is_array($categories) && !empty($categories)) {
                                        foreach ($categories as $category) {
                                            ?>
                                            <li data-filter=".<?php echo $category->slug; ?>" class="<?php echo $category->slug; ?>">
                                                <a href="#<?php echo $category->slug; ?>"><?php echo $category->name; ?></a>
                                            </li>
                                            <?php
                                        }
                                    }
                                    ?>
                                </ul>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="isotope col-md-12 col-xs-12 col-sm-12 padding_0">
                            <?php
                            global $wp_query, $post;
                            $post_id_page = $post->ID;
                            $args = array('post_type' => 'post', 'post_status' => 'publish', 'order' => 'DESC', 'posts_per_page' => -1, 'category__in' => $cat_display_array);
                            $loop = new WP_Query($args);
                            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-4 col-sm-4 col-xs-12 <?php echo $termslug; ?> portfolio_single">
                                    <div class="portfolio_content">
                                        <?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="effect_portfolio"></div>
                                        <div class="port_content"><h3><a href='<?php the_permalink(); ?>' class="text-capitalize"><?php the_title(); ?></a></h3>
                                            <div class="portfolio-tag text-capitalize">
                                                <?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 . '<a href="#">' . $term->name . '</a>';
                                                        $separtor = '<span> , </span>';
                                                    }
                                                }
                                                ?>
                                            </div>                                        
                                        </div>
                                    </div>
                                </div>
                                <?php
                            endwhile;
                            wp_reset_postdata();
                            ?>
                        </div>
                    </div>
                <?php } ?>
            </div><!-- #content -->
        </div><!-- #primary -->
    </div><!-- .row -->
</div><!-- .container -->
<?php get_footer(); ?>