Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save woogist/5480269 to your computer and use it in GitHub Desktop.
Display a slider of related posts at the bottom of a post. Posts are filtered by both tags and categories.
/*
* Woo Related posts slider hooked on woo_post_after
*/
function woo_related_posts_slider() {
global $post;
if( is_single() ){
$extra_args = array();
$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);
}
}
$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'] = 'true';
$extra_args['limit'] = '6';
$extra_args['overlay'] = 'full';
$extra_args['layout'] = 'text-bottom';
wooslider( array( 'slider_type' => 'posts', 'smoothheight' => 'true', 'randomize' => 'true' ), $extra_args );
}
}
add_action( 'woo_post_after', 'woo_related_posts_slider' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment