Last active
December 18, 2015 18:38
-
-
Save bentedder/5826698 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: Rollup Posts | |
Plugin URI: http://www.bentedder.com | |
Description: Rollup posts from specific categories with styles | |
Version: 1.0 | |
Author: Ben Tedder | |
Author URI: http://www.bentedder.com | |
License: GPL2 | |
*/ | |
function bt_rollup_handler($atts, $content = null) { | |
// start collecting information from the output buffer | |
ob_start(); | |
// extract the arguments from the shortcode and set defaults | |
extract( shortcode_atts( array( | |
'category' => 1, | |
'style' => 'grid', | |
'limit' => 1 | |
), $atts ) ); | |
// set the arguments for the query | |
$args = array( | |
'cat' => $category, | |
'posts_per_page' => $limit | |
); | |
query_posts( $args ); | |
if (have_posts()) : while (have_posts()) : the_post(); | |
if($style == 'featured') { | |
echo '<div class="rollup-featured">'; | |
echo get_the_post_thumbnail(get_the_ID(), 'smallsquare', array('class' => 'alignleft')); | |
echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a><br/>'; | |
echo '<p>' . get_the_excerpt() . '</p>'; | |
echo '<br style="clear:both;" />'; | |
echo '</div>'; | |
} else if ($style == 'grid') { | |
echo '<div class="rollup-grid">'; | |
echo get_the_post_thumbnail(get_the_ID(), 'smallsquare'); | |
echo '<a href="' . get_permalink() . '">' . get_the_title() . '</a><br/>'; | |
echo '<br style="clear:both;" />'; | |
echo '</div>'; | |
} | |
endwhile; else: | |
echo 'nothing found'; | |
endif; | |
echo '<br style="clear:both;"/>'; | |
// don't forget to reset and output everything | |
wp_reset_query(); | |
$output = ob_get_contents(); | |
ob_end_clean(); | |
return $output; | |
} | |
add_shortcode( 'rollup', 'bt_rollup_handler' ); | |
add_filter( 'excerpt_length', 'custom_excerpt_length' ); | |
function custom_excerpt_length( $length ) { | |
return 10; | |
} | |
function change_excerpt_more( $more ) { | |
return '... <a href="' . get_permalink() . '">Read more</a>'; | |
} | |
add_filter('excerpt_more', 'change_excerpt_more'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment