youcan.php 4.41 KB
<?php 
function fenix_youcan ($atts, $content)
    {
        $atts = shortcode_atts(
            array(
                'category_name' => '',
                'title'         => '',
                'id'            => ''
            ),
            $atts,
            'fenix_youcan'
        );

        $out = '';

        if ($atts['category_name']!=='')
            {
                $out_parts = array(
                    'slides'        => ''
                );
                $args = array(
                    'numberposts'   => -1,
                    'category_name' => $atts['category_name'],
                    'post_type'     => 'post',
                    'order'         => 'ASC'
                );
                $posts = get_posts($args);
                foreach($posts as $key=>$post)
                    {   
                        setup_postdata( $post );

                        $out_parts['slides'].=

                            '<div class="carousel-item'.($key===0?' active':'').' col-12 col-md-4 d-md-block me-md-0 pb-4" data-bs-interval="false">'.
                                '<div class="card rounded-4 overflow-hidden shadow-block border-0 h-100">'.
                                    '<div class="card-header bg-color-3 text-color-4 px-4">'.((int)$key + 1).'</div>'.
                                    '<div class="card-body text-start">'.
                                        '<h5 class="text-color-3 fw-bold">'.$post->post_title.'</h5>'.
                                        $post->post_content.
                                    '</div>'.
                                    '<div class="card-footer border-0 pt-0">'.
                                        '<p class="price text-color-3 fw-bold border-top py-3">'.
                                            (
                                                $post->post_excerpt!=''?
                                                    $post->post_excerpt:
                                                    '&nbsp;'
                                            ).
                                        '</p>'.
                                        '<div class="row mb-4">'.
                                            '<div class="col-6 w-50 text-center">'.
                                                '<a href="'.get_permalink($post).'" class="btn btn-lg btn-style-0 rounded-pill me-md-2">Подробнее</a>'.
                                            '</div>'.
                                            '<div class="col-6 w-50 text-center">'.
                                                '<a href="#fenix_garantii" class="btn btn-lg btn-style-0 rounded-pill ms-md-2">Заказать</a>'.
                                            '</div>'.
                                        '</div>'.
                                    '</div>'.
                                '</div>'.
                            '</div>';
                    }
                wp_reset_postdata();
                unset($key, $post, $posts, $args);

                $out = ''.

                '<!--Вы можете воспользоват-->'.
                '<div id="'.$atts['id'].'" class="container fenix_youcan '.$atts['category_name'].'">'.
                    '<div class="row">'.
                        '<div class="col-12 pt-3 pt-md-5">'.
                            '<h1>'.$atts['title'].'</h1>'.
                        '</div>'.
                    '</div>'.
                    '<!--карусель-->'.
                    '<div id="slider-'.$atts['id'].'" class="carousel slide pb-md-0" data-bs-interval="false" data-ride="carousel" data-pause="hover">'.
                        '<div class="carousel-inner row m-auto">'.
                            $out_parts['slides'].
                        '</div>'.
                        '<button class="carousel-control-prev d-flex d-md-none justify-content-center rounded-pill bg-color-7 text-color-6" type="button" data-bs-target="#slider-'.$atts['id'].'" data-bs-slide="prev" data-icon="arrow_left"></button>'.
                        '<button class="carousel-control-next d-flex d-md-none justify-content-center rounded-pill bg-color-7 text-color-6" type="button" data-bs-target="#slider-'.$atts['id'].'" data-bs-slide="next" data-icon="arrow_right"></button>'.
                    '</div>'.
                '</div>';
                unset($out_parts);
            }
        return $out;
    }
add_shortcode('fenix_youcan', 'fenix_youcan');