Last active
August 29, 2015 14:02
-
-
Save gstricklind/ff4603a0ef8d0d476ecf to your computer and use it in GitHub Desktop.
WordPress: Add number of post excerpts via shortcode
This file contains 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 | |
/** | |
* Excerpts Shortcode | |
*/ | |
//[excerpts display="3"] | |
function kedc_shortcode_excerpts($atts) { | |
extract( shortcode_atts( array( | |
'display' => '' | |
), $atts) ); | |
$query_posts = new WP_Query('posts_per_page=' . $display); | |
$list = '<ul class="excerpts">'; | |
while($query_posts->have_posts()) : $query_posts->the_post(); | |
$list .= '<li>' . '<h4 class="excerpt-header"><a href="'. get_permalink() . '">' . get_the_title() . '</a></h4>' . '<p class="excerpt-date">' . get_the_date() . '</p>' . '<p class="excerpt-content">' . get_the_excerpt() . '</p>' . '<a class="read-more" href="'. get_permalink() . '"> Continue reading →</a>' . '</li>'; | |
endwhile; | |
wp_reset_query(); | |
return $list . '</ul>'; | |
} | |
add_shortcode('excerpts', 'kedc_shortcode_excerpts'); | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment