/**
  * Output the form
  *
  * @param array $atts
  */
 public static function output($atts, $content = null)
 {
     global $post, $wp;
     $old_post = $post;
     extract(shortcode_atts(SendPress_SC_Recent_Posts::options(), $atts));
     $args = array('orderby' => 'date', 'order' => 'DESC', 'showposts' => $posts, 'post_status' => 'publish');
     if ($uid > 0) {
         $args['author'] = $uid;
     }
     if (strlen($readmoretext) === 0) {
         $readmoretext = 'Read More';
     }
     if (strlen($imgalign) === 0) {
         $imgalign = 'left';
     }
     if (strlen($imgcolwidth) === 0) {
         $imgcolwidth = '30%';
     }
     if (strlen($textcolwidth) === 0) {
         $textcolwidth = '65%';
     }
     if (strlen($styletitle) === 0) {
         $styletitle = '';
     }
     if (strlen($stylereadmore) === 0) {
         $stylereadmore = '';
     }
     if (strlen($featuredimg) === 0) {
         $featuredimg = 'thumbnail';
     }
     if (strlen($cat) > 0) {
         $args['cat'] = $cat;
     }
     if (strlen($category_name) > 0) {
         $args['category_name'] = $category_name;
     }
     if (strlen($tag) > 0) {
         $args['tag'] = $tag;
     }
     //SendPress_Error::log($args);
     $return_string = '';
     if ($content) {
         $return_string = $content;
     }
     //$margin = ($alternate && strtolower($imgalign) === 'left') ? '0px 10px 10px 0px' : '0px 0px 10px 10px';
     //$return_string .= '<div>';
     //query_posts($args);
     $query = new WP_Query($args);
     if ($query->have_posts()) {
         while ($query->have_posts()) {
             $query->the_post();
             if (has_post_thumbnail()) {
                 //reset the template because we have an image
                 $template = strtolower($imgalign) === 'left' ? SendPress_SC_Recent_Posts::post_img_left() : SendPress_SC_Recent_Posts::post_img_right();
                 $img = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), $featuredimg);
                 $template = str_replace('{sp-post-image}', $img[0], $template);
             } else {
                 $template = SendPress_SC_Recent_Posts::post_text_only();
             }
             $template = str_replace('{sp-post-link}', get_permalink(), $template);
             $template = str_replace('{sp-post-title}', get_the_title(), $template);
             $template = str_replace('{sp-post-excerpt}', get_the_excerpt(), $template);
             $template = str_replace('{sp-post-readmore}', $readmoretext, $template);
             $template = str_replace('{sp-post-img-col-width}', $imgcolwidth, $template);
             $template = str_replace('{sp-post-text-col-width}', $textcolwidth, $template);
             $template = str_replace('{sp-post-style-title}', $styletitle, $template);
             $template = str_replace('{sp-post-style-readmore}', $stylereadmore, $template);
             $imgalign = $alternate && strtolower($imgalign) === 'left' ? 'right' : 'left';
             $return_string .= $template;
             $template = '';
         }
     }
     wp_reset_postdata();
     //$return_string .= '</div>';
     wp_reset_query();
     $post = $old_post;
     return $return_string;
 }
 /**
  * Output the form
  *
  * @param array $atts
  */
 public static function output($atts, $content = null)
 {
     global $post, $wp;
     $old_post = $post;
     extract(shortcode_atts(SendPress_SC_Recent_Posts::options(), $atts));
     $args = array('orderby' => 'date', 'order' => 'DESC', 'showposts' => $posts, 'post_status' => 'publish');
     if ($uid > 0) {
         $args['author'] = $uid;
     }
     if (strlen($readmoretext) === 0) {
         $readmoretext = 'Read More';
     }
     if (strlen($imgalign) === 0) {
         $imgalign = 'left';
     }
     if (strlen($imgcolwidth) === 0) {
         $imgcolwidth = '30%';
     }
     if (strlen($textcolwidth) === 0) {
         $textcolwidth = '65%';
     }
     if (strlen($styletitle) === 0) {
         $styletitle = '';
     }
     if (strlen($stylereadmore) === 0) {
         $stylereadmore = '';
     }
     if (strlen($featuredimg) === 0) {
         $featuredimg = 'thumbnail';
     }
     if (strlen($cat) > 0) {
         $args['cat'] = $cat;
     }
     if (strlen($category_name) > 0) {
         $args['category_name'] = $category_name;
     }
     if (strlen($tag) > 0) {
         $args['tag'] = $tag;
     }
     if (strlen($datespan) > 0) {
         $after = get_date_from_gmt(date('Y-m-d H:i:s', strtotime('-1 day')));
         $before = get_date_from_gmt(date('Y-m-d H:i:s', strtotime('now')));
         if (is_numeric($datespan)) {
             $after = get_date_from_gmt(date('Y-m-d H:i:s', strtotime('-' . $datespan . ' day')));
             $before = get_date_from_gmt(date('Y-m-d H:i:s', strtotime('now')));
         }
         if ($datespan === 'weekly') {
             $after = get_date_from_gmt(date('Y-m-d H:i:s', strtotime('-1 week')));
             $before = get_date_from_gmt(date('Y-m-d H:i:s', strtotime('now')));
         }
         $args['date_query'] = array(array('after' => $after, 'before' => $before, 'inclusive' => true));
     }
     if ($columns < 1) {
         $columns = 1;
     }
     $return_string = '';
     if ($content) {
         $return_string = $content;
     }
     $query = new WP_Query($args);
     if ($query->have_posts()) {
         $number_of_columns = 1;
         if ($query->found_posts > 1) {
             $number_of_columns = $columns;
         }
         if ($number_of_columns > 3) {
             $number_of_columns = 3;
         }
         $column_template = "";
         $col1 = "";
         $col2 = "";
         $col3 = "";
         switch ($number_of_columns) {
             case 2:
                 $column_template = SendPress_Data::two_column();
                 break;
             case 3:
                 $column_template = SendPress_Data::three_column();
                 break;
         }
         $idx = 0;
         $current_column = 0;
         while ($query->have_posts()) {
             $query->the_post();
             if (has_post_thumbnail()) {
                 //reset the template because we have an image
                 $template = strtolower($imgalign) === 'left' ? SendPress_Data::post_img_left() : SendPress_Data::post_img_right();
                 $img = wp_get_attachment_image_src(get_post_thumbnail_id(get_the_ID()), $featuredimg);
                 $template = str_replace('{sp-post-image}', $img[0], $template);
             } else {
                 $template = SendPress_Data::post_text_only();
             }
             $template = str_replace('{sp-post-link}', get_permalink(), $template);
             $template = str_replace('{sp-post-title}', get_the_title(), $template);
             $template = str_replace('{sp-post-excerpt}', get_the_excerpt(), $template);
             $template = str_replace('{sp-post-readmore}', $readmoretext, $template);
             $template = str_replace('{sp-post-img-col-width}', $imgcolwidth, $template);
             $template = str_replace('{sp-post-text-col-width}', $textcolwidth, $template);
             $template = str_replace('{sp-post-style-title}', $styletitle, $template);
             $template = str_replace('{sp-post-style-readmore}', $stylereadmore, $template);
             $imgalign = $alternate && strtolower($imgalign) === 'left' ? 'right' : 'left';
             //put things into columns always
             if ($number_of_columns < 2) {
                 $col1 .= $template;
             } else {
                 switch ($current_column) {
                     case 0:
                         $col1 .= $template;
                         break;
                     case 1:
                         $col2 .= $template;
                         break;
                     case 2:
                         $col3 .= $template;
                         break;
                 }
             }
             $template = '';
             $idx++;
             $current_column++;
             if ($current_column == $number_of_columns) {
                 $current_column = 0;
             }
         }
     }
     if (strlen($column_template) === 0) {
         $return_string = $col1;
     } else {
         //add columns to column template
         $column_template = str_replace('{sp-col-1}', $col1, $column_template);
         $column_template = str_replace('{sp-col-2}', $col2, $column_template);
         $column_template = str_replace('{sp-col-3}', $col3, $column_template);
         $return_string = $column_template;
     }
     wp_reset_postdata();
     //$return_string .= '</div>';
     wp_reset_query();
     $post = $old_post;
     return $return_string;
 }