Skip to content

Instantly share code, notes, and snippets.

@devuri
Created January 31, 2017 18:43
Show Gist options
  • Save devuri/808c15c637540762c3cd01a67e619f56 to your computer and use it in GitHub Desktop.
Save devuri/808c15c637540762c3cd01a67e619f56 to your computer and use it in GitHub Desktop.
<?php
// shortcode
add_shortcode( 'foobar', 'foobar_func' );
function foobar_func( $atts ){
// php only
$recent_posts = wp_get_recent_posts(array(
'numberposts' => 3,
'category' => 15,
'post_status' => 'publish'
));
foreach( $recent_posts as $recent ){
echo '<a href="'. get_permalink($recent["ID"]) . ' "> ' . $recent[post_title] . '</a>' ;
echo ' | '. date( 'l F jS', strtotime( $recent['post_date'] ) );
echo '<hr/>';
} wp_reset_query();
}
?>
[foobar]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment