contacts.php 2.03 KB
<?php 
function fenix_contacts ($atts, $content)
    {
        $atts = shortcode_atts(
            array(
                'post'  => '',
                'id'    => '',
                'url'   => ''
            ),
            $atts,
            'fenix_contacts'
        );

        $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 = ''.
                            '<!--КОНТАКТЫ-->'.
                            '<div id="'.$atts['id'].'" class="fenix-contacts gradient shadow-1"'.(has_post_thumbnail($post->ID)?' style="background-image: url('.get_the_post_thumbnail_url($post->ID, 'full').');"':'').'>'.
                                '<div class="container">'.
                                    '<div class="row flex-md-row-reverse">'.
                                        '<div class="col-12 col-md-7 ">'.
                                            '<iframe loading="lazy" src="'.$atts['url'].'" width="100%" height="100%" frameborder="0" class="img-fluid h-100"></iframe>'.
                                        '</div>'.
                                        '<div class="col-12 col-md-5">'.
                                            '<h1>'.($post->post_excerpt===''?$post->post_title:$post->post_excerpt).'</h1>'.
                                            $post->post_content.
                                        '</div>'.
                                    '</div>'.
                                '</div>'.
                            '</div>';
                    }
                wp_reset_postdata();

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