Last active
May 26, 2016 00:07
-
-
Save BruceMcKinnon/307a322a36bf8b84d0d7f3ea5b8ac0af to your computer and use it in GitHub Desktop.
WP shortcode for displaying a fixed number of posts from a single category
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
function ccc_latest_post($atts, $content=null){ | |
echo '<ul>'; | |
$myposts = get_posts( array('posts_per_page' => 3, 'category_name' => 'news') ); | |
foreach ( $myposts as $post ) : setup_postdata( $post ); ?> | |
<li> | |
<h4><a href="<?php echo get_the_permalink($post->ID); ?>"><?php echo get_the_title($post->ID); ?></a></h4> | |
<p><?php echo get_the_excerpt($post->ID); ?> <a href="<?php echo get_the_permalink($post->ID); ?>"><em>Read more...</em></a></p> | |
</li> | |
<?php endforeach; | |
wp_reset_postdata(); | |
echo '</ul>'; | |
} | |
add_shortcode('latest-posts', 'ccc_latest_post'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment