<?php
 function faqShortcode($isHome = 0) {
    global $query;

    $args = array('post_type' => 'lz_faq');

    if (!empty($pageId)) {
        $args['page_id'] = absint($pageId);
    } else {
        $args['paged'] = max(1, get_query_var('paged'));
    }

    if(!empty($isHome) && $isHome == 1){
        $cols = get_theme_mod('faq_section_npp_count', 4);
        $cols++;
        $args['posts_per_page'] = $cols;
    }else{
        $args['posts_per_page'] = (!empty($args['posts_per_page'])) ? $args['posts_per_page'] : -1;
         // $cols = 5;
    }
    $faqPageId = get_theme_mod('faq_section_page_link');
    $query = new WP_Query($args);
    ob_start();
    // print_r($query);
    echo '<div class="faq">';
    if ($query->have_posts()){
        while ($query->have_posts()) : $query->the_post();
            $post = get_post();
            ?>
            <div class="row">
                    <div class="col-md-12 faq-content padding0">
                    <h6 class="faq-title"><?php the_title(); ?></h6>
                    <div class="faq-description">
                        <p><?php
                            if(!empty($isHome) && $isHome==1){
                                if (has_excerpt()) {
                                    echo get_the_excerpt();
                                } else {
                                    echo lz_fitness_excerpt(get_the_content(), 100);
                                }
                                if(!empty($faqPageId)){
                                    echo '<a href="'.get_permalink($faqPageId).'">Read More..</a>';
                                }else{
                                    echo '<a href="'.get_permalink($faqPageId).'">Read More..</a>';
                                }
                            }else{
                                echo get_the_content();
                            }?>
                        </p>
                    </div> 
                </div>
            </div>
            <?php
        endwhile;
    }else{
        for($i=0; $i<$cols; $i++){
            ?>
            <div class="row">
                <div class="col-md-12 faq-content">
                    <h6 class="faq-title">FAQ question </h6>
                    <div class="faq-description">
                        <p><?php
                            if(!empty($isHome) && $isHome==1){
                                ?>
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean pharetra iaculis nunc sed pharetra. Sed faucibus non tellus laoreet finibus.
                                <br>
                                <?php
                                if(!empty($faqPageId)){
                                    echo '<a href="'.get_permalink($faqPageId).'">Read More..</a>';
                                }else{
                                    echo '<a href="'.get_permalink($faqPageId).'">Read More..</a>';
                                }
                            }else{
                                ?>
                                Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean pharetra iaculis nunc sed pharetra. Sed faucibus non tellus laoreet finibus. Cras enim erat, iaculis ac mauris a, faucibus maximus magna. Sed rhoncus quam id enim laoreet, vel vehicula purus consequat. Donec sed dapibus ipsum. Curabitur ultricies, massa sit amet aliquam laoreet, lorem nulla sagittis mauris, id porttitor arcu purus ut sem. Nunc aliquet nec velit sed consectetur. Aliquam aliquam diam varius, dictum libero in, lobortis tellus. Fusce eget tempus purus.

                                Vestibulum pretium gravida augue in semper. Cras eu lorem sed turpis venenatis ultricies quis eget diam. Integer porttitor sem sapien, id vestibulum justo ultricies et. Fusce in efficitur velit. Quisque risus quam, lobortis at neque nec, accumsan semper justo. Pellentesque in ligula dui. Donec vestibulum, ipsum non gravida elementum, magna diam faucibus magna, et interdum ante elit rutrum est. Suspendisse potenti. Quisque vehicula lacinia vulputate. Pellentesque a rhoncus dui, aliquam.
                                <?php
                            }?>
                        </p>
                    </div>  
                </div>
            </div>
            <?php
        }
    }
        echo '</div>';
        ?>
        <script>
            $(function(){
                $('.faq-description').hide();
                $('.faq-title').on('click', function(){
                    $('.faq-description.active').slideToggle(600).removeClass('active');
                    $(this).next().slideToggle(600).toggleClass('active');
                    
                });
            });
        </script>
        
        <?php
        $text = ob_get_contents();
        ob_clean();
        ob_end_flush();
    wp_reset_postdata();
    // echo $text;
    return $text;
}
add_shortcode('FAQS', 'faqShortcode');




    