Pankaj Kumar
Forum Replies Created
-
Forum: Plugins
In reply to: [WpF Ultimate Carousel] Products for custom selected terms of custom taxonomyHi i have done some of customization in your plugin file to show the custom taxonomies related product or any of other post types data.
Here is code:-
//shortcode
function wpf_ultimate_carousel_shortcode($atts){
extract( shortcode_atts( array(
‘post_type’ => ‘post’,
‘category’ => ”,
‘count’ => ‘-1’,
‘taxonomy’ => ‘category_name’,
‘name’ => ‘carousel’,
‘slides’ => ‘4’,
‘scroll’ => ‘1’,
‘autoplay’ => ‘false’,
‘speed’ => ‘2000’,
‘title_color’ => ‘#000000’,
‘title_bg_color’ => ”,
‘link_color’ => ‘#222222’,
‘title’ => ‘More…’
), $atts, ‘wpf_carousel’ ) );/*——————————————————————*/
$cterm_ids = array();
foreach( (get_the_terms(get_the_ID(), $taxonomy )) as $cterm ) {
$cterm_ids[] = $cterm->term_id;
}/*——————————————————————*/
global $post;
$args = array( ‘posts_per_page’ => $count, ‘post_type’ => $post_type, $taxonomy => $category);
/*——————————————————————*/
if(isset($cterm_ids) && !empty($cterm_ids)) {$args = array( ‘posts_per_page’ => $count, ‘post_type’ => $post_type, $taxonomy => $category,
‘tax_query’ => array(
‘relation’ => ‘AND’,
array(
‘taxonomy’ => $taxonomy,
‘field’ => ‘term_id’,
‘terms’ => $cterm_ids,
‘operator’ => ‘IN’,
),
)
);
}
/*——————————————————————*/$myposts = get_posts( $args );
$list = ‘
<script type=”text/javascript”>
jQuery(document).ready(function(){
jQuery(“#wpf_’.$name.'”).slick({
slidesToShow: ‘.$slides.’,
slidesToScroll: ‘.$scroll.’,
autoplay: ‘.$autoplay.’,
autoplaySpeed: ‘.$speed.’,
});});
</script>
<div class=”wpf_carousel_container” style=”width:80%;margin:0 auto;”>
<h2 style=”color:’.$title_color.’;background:’.$title_bg_color.’;”>’.$title.'</h2>
<div id=”wpf_’.$name.'”>’;foreach( $myposts as $post ) : setup_postdata($post);
$post_thumbnail= get_the_post_thumbnail( $post->ID, ‘wpf-carousel-image-big’,array(‘alt’ => get_the_title(),’title’ => get_the_title()));
$list .= ‘<div class=”wpf_slides”>
‘.$post_thumbnail.’
<h2>‘.ShortenText(get_the_title()).’</h2>
</div>‘;
endforeach;
$list.= ‘</div></div>’;
wp_reset_query();
return $list;
}
add_shortcode(‘wpf_carousel’, ‘wpf_ultimate_carousel_shortcode’);