-
-
Save billerickson/9d636c21c18f571c43b6 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: Display Posts Shortcode | |
* Plugin URI: http://www.billerickson.net/shortcode-to-display-posts/ | |
* Description: Display a listing of posts using the [display-posts] shortcode | |
* Version: 0.1.3 | |
* Author: Bill Erickson | |
* Author URI: http://www.billerickson.net | |
* | |
* This program is free software; you can redistribute it and/or modify it under the terms of the GNU | |
* General Public License version 2, as published by the Free Software Foundation. You may NOT assume | |
* that you can use any other version of the GPL. | |
* | |
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without | |
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
* | |
* @package Display Posts | |
* @version 0.1.3 | |
* @author Bill Erickson | |
* @copyright Copyright (c) 2011, Bill Erickson | |
* @link http://www.billerickson.net/shortcode-to-display-posts/ | |
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html | |
*/ | |
// Create the shortcode | |
add_shortcode(‘display-posts’, ‘be_display_posts_shortcode’); | |
function be_display_posts_shortcode($atts) { | |
extract( shortcode_atts( array( | |
‘tag’ => ”, | |
‘category’ => ”, | |
‘posts_per_page’ => ’10’, | |
‘include_date’ => ”, | |
‘order’ => ‘DESC’, | |
‘orderby’ => ‘date’, | |
‘image_size’ => ”, | |
‘include_excerpt’ => ” | |
), $atts ) ); | |
$args = array( | |
‘tag’ => $tag, | |
‘category_name’ => $category, | |
‘posts_per_page’ => $posts_per_page, | |
‘order’ => $order, | |
‘orderby’ => $orderby | |
); | |
$return = ”; | |
$listing = new WP_Query($args); | |
if ( $listing->have_posts() ): | |
$return .= ”; | |
while ( $listing->have_posts() ): $listing->the_post(); global $post; | |
$return .= ”; | |
if ($image_size) $return .= ‘‘. get_the_post_thumbnail($post->ID, $image_size).’ ‘; | |
$return .= ‘‘. get_the_title() .’‘; | |
if ($include_excerpt) $return .=”. get_the_excerpt() .”; | |
if ($include_date) $return .= ‘ (‘. get_the_date(‘n/j/Y’) .’)'; | |
$return .= ”; | |
endwhile; | |
$return .= ”; | |
endif; wp_reset_query(); | |
if (!empty($return)) return $return; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment