faq.php 2.43 KB
<?php 
function fenix_faq ($atts)
    {
        $atts = shortcode_atts(
            array(
                'id' => '',
                'title'=>''
            ),
            $atts,
            'fenix_faq'
        );

        $out = ''.
            '<!--FAQ-->'.
            '<div id="'.$atts['category_name'].'" class="fenix-faq shadow-1"'.(has_post_thumbnail($post->ID)?' style="background-image: url('.get_the_post_thumbnail_url($post->ID, 'full').');"':'').'>'.
                '<div class="container">'.
                    '<h1>'.$atts['title'].'</h1>'.
                    '<div class="row">'.
                        '<div class="col-12">'.
                            '<div class="accordion accordion-flush" id="accordionFlushFAQ">';
        $args = array(
            'numberposts'   => -1,
            'category_name' => 'faq',
            'post_type'     => 'post',
            'order'         => 'ASC'
        );
        $posts = get_posts($args);
        foreach($posts as $key=>$post)
            {   
                setup_postdata( $post );
                $out.= ''.
                    '<div class="accordion-item bg-custom-5">'.
                        '<h2 class="accordion-header" id="flush-heading-'.$key.'">'.
                            '<button class="accordion-button collapsed text-color-1" type="button" data-bs-toggle="collapse" data-bs-target="#flush-collapse-'.$key.'" aria-expanded="false" aria-controls="flush-collapse-'.$key.'">'.$post->post_title.'</button>'.
                        '</h2>'.
                        '<div id="flush-collapse-'.$key.'" class="accordion-collapse collapse" aria-labelledby="flush-heading-'.$key.'" data-bs-parent="#accordionFlushFAQ">'.
                            '<div class="accordion-body">'.
                            $post->post_content.
                            '</div>'.
                        '</div>'.
                    '</div>';
            }
        wp_reset_postdata();
        unset($key, $post, $posts, $args);

        $out.= ''.
                            '</div>'.
                            '<div class="text-center">'.
                                '<button class="btn btn-lg btn-style-3 rounded-pill btn-down mb-4" role="button" data-icon="arrow_down"></button>'.
                            '</div>'.
                        '</div>'.
                    '</div>'.
                '</div>'.
            '</div>';
            
        return $out;
    }
add_shortcode('fenix_faq', 'fenix_faq');