Created
June 23, 2015 17:30
-
-
Save igmoweb/7b4046f83a678f558baf to your computer and use it in GitHub Desktop.
posts-list-shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_shortcode( 'posts-list', 'ignacio_posts_list_shortcode' ); | |
function ignacio_posts_list_shortcode( $atts ) { | |
$defaults = array( | |
'items' => 3 | |
); | |
$atts = wp_parse_args( $atts, $defaults ); | |
$args = array( | |
'ignore_sticky_posts' => true, | |
'posts_per_page' => $atts['items'], | |
'post_type' => 'post', | |
'post_status' => 'publish' | |
); | |
$posts = get_posts( $args ); | |
$html = '<ol>'; | |
foreach ( $posts as $post ) { | |
$html .= '<li style="border:1px solid black;margin-bottom:20px;">'; | |
$html .= get_the_post_thumbnail( $post->ID, 'thumbnail' ); | |
$html .= '<h2>' . get_the_title( $post->ID ) . '</h2>'; | |
$html .= '</li>'; | |
} | |
$html .= '</ol>'; | |
return $html; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment