<?php



// [xs_blog]   
function xs_blog($atts) {
    extract(shortcode_atts(array(
        'count' => 3
                    ), $atts));

    global $post, $within_section;
    $html = '';
    // WP_Query arguments
    $args = array(
        'posts_per_page' => $count,
    );
    // The Query
    $query = new WP_Query($args);

    // The Loop
    if ($query->have_posts()) {
        while ($query->have_posts()) {
            $query->the_post();
            $thumb = esc_url(get_template_directory_uri() . '/theme-assets/img/blog/post-thumbnail.jpg');
            if (has_post_thumbnail()) {
                $large_image_url = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), 'medium');
                $thumb = $large_image_url[0];
            }
            $html .= '<article class="col-md-4 col-sm-4 col-xs-12 front-blog-entry">
                <div class="section">
                        <figure class="post-thumbnail section-blog">
                                ' . xs_posted_on($post->ID, false) . '
                                <a href="' . esc_url(get_post_permalink($post->ID)) . '" title="' . esc_html($post->post_title) . '" class="hoverImg">
                                <i class="fa fa-chain"></i>
                                <img width="360" height="229" src="' . $thumb . '" alt="" class="img-responsive" />
                                </a>
                        </figure>
                        <header class="post-header">
                                <a href="' . get_the_permalink() . '"><h5>' . esc_html($post->post_title) . '</h5></a>

                        </header>
                        <div class="post-content">
                                <p>' . the_excerpt_max_charlength(140) . '</p>
                                <p class="text-center post-footer"><a href="' . esc_url(get_post_permalink($post->ID)) . '" title="' . __('Read More', 'xs') . '" class="btn btn-default">' . __('Read More', 'xs') . ' <i class="fa fa-angle-right"></i></a></p>
                        </div>
                </div>
                <!--end-of-section-->
        </article>';
        }
    }
    // Restore original Post Data
    wp_reset_postdata();

    if ($within_section == 'y') {
        return '<div class="bottom-margin clearfix"></div><div class="row">' . $html . '</div>';
    } else {
        return '<div id="standalone-section"><div class="row">' . $html . '</div></div>';
    }
}

add_shortcode('xs_blog', 'xs_blog');
