<?php
function myIthelpline_posts_shortcode($atts, $content = null)
{
global $post;
extract(shortcode_atts(array(
'cat' => '',
'num' => '5',
'order' => 'DESC',
'orderby' => '',
), $atts));
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args = array(
'cat' => $cat,
'posts_per_page' => $num,
'order' => $order,
'orderby' => $orderby,
);
$output = '';
$query = new WP_Query($args);
if ($query->have_posts()) : $output;
while ($query->have_posts()) : $query->the_post();
$output .= '<article id="post-' . get_the_ID() . '" class="' . implode(' ', get_post_class()) . '">';
$output .= '<div class="row">';
if (has_post_thumbnail()) {
$output .= '<div class="col-md-6">';
$output .= '<a href="' . get_permalink() . '" title="' . the_title('', '', false) . '">';
$output .= get_the_post_thumbnail(get_the_id(), 'medium', array('class' => 'img-responsive aligncenter'));
$output .= '</a>';
$output .= '</div>';
$output .= '<div class="col-md-6">';
$output .= '<h4 class="post-title"><span><a href="' . get_permalink() . '" title="' . the_title('', '', false) . '">' . the_title('', '', false) . '</a></span></h4>';
$output .= get_the_excerpt();
$output .= '</div>';
$output .= '</div>';
$output .= '<div class="post-info">';
$output .= '</div>';
} else {
$output .= '<div class="col-md-12">';
$output .= '<h4 class="post-title"><span><a href="' . get_permalink() . '" title="' . the_title('', '', false) . '">' . the_title('', '', false) . '</a></span></h4>';
$output .= get_the_excerpt();
$output .= '</div>';
$output .= '</div>';
$output .= '<div class="post-info">';
$output .= '</div>';
}
$output .= '</article>';
endwhile;
global $wp_query;
$args_pagi = array(
'base' => add_query_arg('paged', '%#%'),
'total' => $query->max_num_pages,
'current' => $paged
);
$output .= '<div class="post-nav">';
$output .= paginate_links($args_pagi);
$output .= '</div>';
else :
$output .= '<p>Sorry, there are no posts to display</p>';
endif;
wp_reset_postdata();
return $output;
}
add_shortcode('blog_posts', 'myIthelpline_posts_shortcode'); ?>
[blog_posts num="5" cat="41"]