Created
August 19, 2016 03:34
-
-
Save phil-hudson/4a8883451cf43c0c1090aee2688a39b3 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* Plugin Name: Recent Posts Shortcode | |
* Plugin URI: http://www.phil-hudson.com/recent-posts-shortcode-wordpress-plugin/ | |
* Description: A simple, open-source plugin to return your most recent posts via a shortcode. Use on any post or page: [recentPosts amountOfPosts="2"]. For more details please see: http://phil-hudson.com/recent-posts-shortcode-wordpress-plugin/ | |
* Version: 0.1 | |
* Stable: 4.2.2 | |
* Author: Phil Hudson | |
* Author URI: http://www.phil-hudson.com | |
* License: GPL12 | |
*/ | |
function recentPosts($atts){ | |
$params = shortcode_atts( array( | |
'amountOfPosts' => 1, | |
), $atts ); | |
$getpost = get_posts( array('number' => $params['amountOfPosts']) ); | |
$return = ''; | |
foreach ($getpost as $post) { | |
$return .= "<div style="font-size: x-large" id=\"". $post->ID ."\"><h1 class=\"entry-title\">" . $post->post_title . "</h1><div class=\"entry-content\">" . $post->post_excerpt . "</div>"; | |
$return .= "<br /><a style="font-size: large" href='" . get_permalink($post->ID) . "'><em>read more →</em></a></div></br>"; | |
} | |
return $return; | |
} | |
add_shortcode('recentPosts', 'recentPosts'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment