/*
Theme Name: The Newspaper Child
Theme URI: http://cmsmasters.net/the-newspaper-child/
Author: cmsmasters
Author URI: http://cmsmasters.net/
Description: The Newspaper Child Theme
Template: the-newspaper
Version: 1.0.0
License:
License URI:
Text Domain: the-newspaper-child
Tags: one-column, two-columns, three-columns, four-columns, left-sidebar, right-sidebar, custom-background, custom-colors, custom-header, custom-menu, editor-style, featured-image-header, featured-images, flexible-header, full-width-template, microformats, post-formats, rtl-language-support, sticky-post, theme-options, threaded-comments, translation-ready
*/

function show_latest_local_news($atts) {
    ob_start();
    $atts = shortcode_atts(array(
        'category' => 'local-news',
        'posts_per_page' => 6
    ), $atts);
    $query = new WP_Query(array(
        'category_name' => $atts['category'],
        'posts_per_page' => intval($atts['posts_per_page'])
    ));
    if ($query->have_posts()) {
        echo '<div class="latest-local-news">';
        while ($query->have_posts()) {
            $query->the_post();
            echo '<article>';
            if (has_post_thumbnail()) {
                echo '<a href="' . get_permalink() . '">';
                the_post_thumbnail('medium');
                echo '</a>';
            }
            echo '<h3><a href="' . get_permalink() . '">' . get_the_title() . '</a></h3>';
            echo '<p>' . get_the_excerpt() . '</p>';
            echo '</article>';
        }
        echo '</div>';
        wp_reset_postdata();
    }
    return ob_get_clean();
}
add_shortcode('latest_local_news', 'show_latest_local_news');

function clean_assets() {
    wp_enqueue_style('main-style', get_stylesheet_uri());
    wp_enqueue_script('main-js', get_template_directory_uri() . '/assets/js/main.js', array('jquery'), null, true);
}
add_action('wp_enqueue_scripts', 'clean_assets');

