Created
April 29, 2013 07:59
-
-
Save woogist/5480273 to your computer and use it in GitHub Desktop.
Shortcode to display related posts
This file contains hidden or 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
| /* | |
| * 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