open.php 2.35 KB
<?php 
function fenix_open ($atts)
    {
        $atts = shortcode_atts(
            array(
                'post'  => '',
                'id'    => '',
                'link'  => '#'
            ),
            $atts,
            'fenix_open'
        );

        $out = '';

        if ($atts['post']!=='')
            {
                $args = array(
                    'numberposts'   => 1,
                    'post__in'      => array($atts['post']),
                    'order'         => 'ASC',
                    'limit'         => 1
                );
                $posts = get_posts($args);
                foreach($posts as $key=>$post)
                    {   
                        $out = ''.
                        '<!--Откройте свою прибыльную клинику с нами от 4х месяцев-->'.
                        '<div id="'.$atts['id'].'" class="container fenix_open">'.
                            '<div class="row flex-md-row-reverse align-items-center">'.
                                (
                                    has_post_thumbnail($post->ID)?
                                        '<div class="col-12 col-md-6">'.
                                            '<img src="'.get_the_post_thumbnail_url($post->ID, 'full').'" class="img-fluid mb-2 mb-md-0"/>'.
                                        '</div>':
                                        ''
                                ).
                                '<div class="col-12 col-md-6">'.
                                    '<h1>'.$post->post_title.'</h1>'.
                                    '<div class="mb-5">'.
                                        $post->post_content.
                                        '<br/>'.
                                    '</div>'.
                                    '<div class="text-center text-md-start">'.
                                        '<a href="'.$atts['link'].'" class="btn btn-lg btn-style-0 rounded-pill mb-4">Получить консультацию</a>'.
                                    '</div>'.
                                '</div>'.
                            '</div>'.
                        '</div>';
                    }
                wp_reset_postdata();

                unset($key, $post, $posts, $args);
            }
        return $out;
    }
add_shortcode('fenix_open', 'fenix_open');