Created
August 13, 2017 17:21
-
-
Save dimaslanjaka/f4037ebe1543d8ec5953286e0086cfcc 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
// Add Shortcode | |
function recent_post_src( $atts ) { | |
// Attributes | |
$atts = shortcode_atts( | |
array( | |
'posts' => '5', | |
), | |
$atts, | |
'recent-posts' | |
); | |
// Query | |
$the_query = new WP_Query( array ( 'posts_per_page' => $atts['posts'] ) ); | |
// Posts | |
$output = '<style>ul.custom { | |
list-style-type: none; | |
margin: 0; | |
padding: 0; | |
}</style>Recently Published:<br><ul class="custom">'; | |
while ( $the_query->have_posts() ) : | |
$the_query->the_post(); | |
$output .= '<li><a href="' . get_the_permalink() . '" rel="follow">' . get_the_title() . '</a></li>'; | |
endwhile; | |
$output .= '</ul>'; | |
// Reset post data | |
wp_reset_postdata(); | |
// Return code | |
return $output; | |
} | |
add_shortcode( 'recent-posts', 'recent_post_src' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment