<?php
/*subject*/
function subjectShortCode($pageId = null, $isCustomizer = false, $i = null) {

    ob_start();

    $args = array('post_type' => 'our-subjects');
    if (!empty($pageId)) {
        $args['page_id'] = absint($pageId);
    }
    $args['posts_per_page'] = -1;
    $colCls = '';
    // if($isCustomizer == true){
    $cols = get_theme_mod('subject_npp_count',2);  
    $subjects_page_icon1 = get_theme_mod('subjects_page_icon1'.$i);
    ++$cols;
    switch ($cols) {
        case 1:
        $colCls = 'col-md-12 col-sm-12';
        break;
        case 2: 
        $colCls = 'col-md-6 col-sm-6';
        break;
        case 3:
        case 5:
        case 6:
        case 9:
        case 11:
        case 13:
        case 15:
        case 17:
        case 19:
        case 21:
        case 23:
        $colCls = 'col-md-4 col-sm-6';
        break;
        default: 
        $colCls = 'col-md-3 col-sm-6';
        break;
        }
    // }
        $text = '';
        $query = new WP_Query($args);
        if ($query->have_posts()):
            $postN = 0;

            while ($query->have_posts()) : $query->the_post();
                $luzuk_image = wp_get_attachment_image_src(get_post_thumbnail_id(), 'total-subject-thumb');
                $post = get_post();

                ?>

                <div class="<?php echo $colCls; ?> single-subject-bx wow zoomIn">
                   
                    <div subjectinn-match-height="groupName" class="single-subject">

                         <div class="subject-icon">
                             <a href="<?php the_permalink(); ?>">
                           <i class="<?php echo $subjects_page_icon1; ?>"></i>
                            </a>
                             <a href="<?php the_permalink(); ?>">
                                <div class="subject-img-overlay">
                           <?php
                            if (has_post_thumbnail()) {
                                $image_url = $luzuk_image[0];
                            } else {
                                $image_url = get_template_directory_uri() . '/images/subjects.jpg';
                            }
                            ?>                                                        
                                <img class="img-responsive" src="<?php echo esc_url($image_url); ?>" alt="<?php the_title(); ?>" />
                            </div>
                                 </a>
                            </div>
                        <h4 class="post-title inner-area-title wow fadeInDown"><?php the_title(); ?></h4>
                        <p class="section-area-text">
                            <?php

                            if(has_excerpt()){
                              echo get_the_excerpt();
                             }else{
                              echo luzuk_excerpt( get_the_content() , 100 );
                             } 
                            ?>
                        </p>
                        <div class="subject-content">
                            <ul class="sub-btn">
                                <li> <a href="<?php the_permalink(); ?>"><i class="fa fa-chevron-right"></i></a></li>
                           </ul>
                       </div>
                    </div>
      <script>
    var matchHeight = function () {
    
    function init() {
        eventListeners();
        matchHeight();
    }
    
    function eventListeners(){
        $(window).on('resize', function() {
            matchHeight();
        });
    }
    
    function matchHeight(){
        var groupName = $('[subjectinn-match-height]');
        var groupHeights = [];
        
        groupName.css('min-height', 'auto');
        
        groupName.each(function() {
            groupHeights.push($(this).outerHeight());
        });
        
        var maxHeight = Math.max.apply(null, groupHeights);
        groupName.css('min-height', maxHeight);
    };
    
    return {
        init: init
    };
    
} ();

$(document).ready(function() {
    matchHeight.init();
});
</script>

                </div>


                <?php
            endwhile;
            $text = ob_get_contents();
            ob_clean();
        endif;
        wp_reset_postdata();
        return $text;
    }

add_shortcode('SUBJECTS', 'subjectShortCode');

