opisanie.php 1.73 KB
<?php 
function fenix_opisanie ($atts, $content)
    {
        $atts = shortcode_atts(
            array(
                'post'  => '',
                'id'    => ''
            ),
            $atts,
            'fenix_opisanie'
        );

        $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-opisanie shadow-1 gradient"'.(has_post_thumbnail($post->ID)?' style="background-image: url('.get_the_post_thumbnail_url($post->ID, 'full').');"':'').'>'.
                                '<div class="container text-color-1 py-3">'.
                                    '<div class="row">'.
                                        '<div class="col-12">'.
                                            '<h1 class="text-start mb-3 mb-md-5">'.($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_opisanie', 'fenix_opisanie');