Shortcode - Restituisce la lista degli ultimi articoli
// Shortcode per visualizzare gli ultimi post
add_shortcode( 'list-posts', 'list_posts_shortcode' );
function list_posts_shortcode( $atts ) {
ob_start();
// define attributes and their defaults
extract( shortcode_atts( array (
'type' => 'post',
'order' => 'ASC',
'orderby' => 'date',
'posts_per_page' => -1
), $atts ) );
// define query parameters based on attributes
$options = array(
'post_type' => $type,
'order' => $order,
'orderby' => $orderby,
'posts_per_page' => $posts_per_page
);
$q = new WP_Query( $options );
$list = '<ul class="recent-posts">';
while($q->have_posts()) : $q->the_post();
$list .= '<li><a href="' . get_permalink() . '">' . get_the_title() . '</a>' . '<br />' . get_the_excerpt() . '</li>';
endwhile;
wp_reset_query();
return $list . '</ul>';
}