Skip to content

Instantly share code, notes, and snippets.

@woogist
Created April 29, 2013 07:59
Show Gist options
  • Select an option

  • Save woogist/5480273 to your computer and use it in GitHub Desktop.

Select an option

Save woogist/5480273 to your computer and use it in GitHub Desktop.
Shortcode to display related posts
/*
* Woo Related Posts Slider Shortcode
*/
function woo_related_posts_slider($atts) {
global $post;
extract( shortcode_atts( array(
'tags' => 'true',
'cats' => 'true',
'link_title' => 'true',
'limit' => '6',
'overlay' => 'full',
'layout' => 'text-bottom'
), $atts ) );
if( is_single() ) {
$extra_args = array();
if($tags == 'true') {
$terms_tags = get_the_terms( $post->ID, 'post_tag' );
$count = 0;
if ( !empty( $terms_tags ) ) {
$extra_args['tag'] = '';
foreach( $terms_tags as $k => $v) {
$count++;
if ( $count > 1 ) {
$extra_args['tag'] .= '+';
}
$extra_args['tag'] .= esc_attr($v->slug);
}
}
}
if($cats == 'true') {
$terms_categories = get_the_terms( $post->ID, 'category' );
$count = 0;
if ( !empty( $terms_categories ) ) {
$extra_args['category'] = '';
foreach ( $terms_categories as $k => $v ) {
$count++;
if ( $count > 1 ) {
$extra_args['category'] .= ',';
}
$extra_args['category'] .= esc_attr( $v->slug );
}
}
}
$extra_args['link_title'] = $link_title;
$extra_args['limit'] = $limit;
$extra_args['overlay'] = $overlay;
$extra_args['layout'] = $layout;
wooslider( array( 'slider_type' => 'posts', 'smoothheight' => 'true', 'randomize' => 'true' ), $extra_args );
}
}
add_shortcode('related_slider', 'woo_related_posts_slider' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment