• I was having issues with the taxonomy attribute in the shortcode. I understood from the included shortcode examples that custom taxonomies were supported – but I was having a problem implementing them myself.

    Just to explain my approach: – I use a custom taxonomy I created called ‘display’ for my theme so that I can specify where I want content (post & pages) to appear in my templates without it being visible in my categories . In this instance I wanted to have posts be selected for the slideshow by the ‘display’ term ‘homepage-slideshow’.

    so I thought this shortcode would work:

    <?php echo do_shortcode('[upzslider intertype="post" interid="home-slideshow" taxoname="display" ]'); ?>

    for some reason my term/custom tax was not getting pulled up correctly and was instead defaulting to the most recent posts.

    From what I can understand by reading the plugin files (I am not a developer as you can see) there are three slider/ or slide types which determine the query method
    The slider checks if the slides are type1(posts) or type 3(custom post type) and if 1 or 3 it uses the slider_getinfo_by_cat function to query the slides,
    and then for everything else (including slider type 2(pages)) it uses the slider_getpages function.

    So following that logic I added an if statement ahead of those two that says if the taxoname is NOT empty – load slider_getinfo_by_term function instead.
    I simplified the slider_getinfo_by_cat function and changed the query syntax (and I probably removed some steps needed)
    and put it in upzSlider.php:

    function slider_getinfo_by_term($taxoname, $term, $number, $fetch,$slider_title_max_char,$slider_title_thumb_max_char,$slider_desc_max_char) {
    	global $post;
    	global $intername; // used as term
    	global $taxonamesc; // taxonomy
    	global $usingshort;
    
           $myposts = get_posts("post_status=\"publish\"&$taxoname=\"$term\"&numberposts=$fetch");
    	$postok_number = 0;
    
    	foreach($myposts as $post) :
    		if(has_post_thumbnail($post->ID)) {
    		$post_perma[] = get_permalink($post->ID);
    		// R?cuperation des options
    		$title = "";
    		$title = tronc_str(__($post->post_title),$slider_title_max_char);
    		$post_title[] = $title;
    
    		$thumb_title = "";
    		$thumb_title = tronc_str(__($post->post_title),$slider_title_thumb_max_char);
    		$post_thumb_title[] = $thumb_title;
    
    		$content = "";
    		$post_excerpt = get_option('slider-contentexrpt');
    		if($post_excerpt==1) {
    		$content = tronc_str(__($post->post_excerpt),$slider_desc_max_char);
    		}
    		else {
    		$content = tronc_str(__($post->post_content),$slider_desc_max_char);
    		}
    		$post_content[] = $content;
    
    		$thumb[] =  get_the_post_thumbnail( $post->ID,'upz-big');
    
    		$thumb_mini[] =  get_the_post_thumbnail( $post->ID,'upz-small');
    
    			if(sizeof($post_title)==$number) {
    			wp_reset_query();
    			return array($post_perma,$post_title,$post_thumb_title,$post_content,$thumb,$thumb_mini);
    			}		
    
    		}
    	endforeach;
    	wp_reset_query();
    	return array($post_perma,$post_title,$post_thumb_title,$post_content,$thumb,$thumb_mini);
    }

    and after this in slider.php

    if($interid!=null && $interid!='') {
    		$slider_cat_id = $interid;
    		}
    		else {
    		$slider_cat_id = get_option('slider-category-id');
    		}

    I added this:

    if($taxoname!=null && $taxoname!='') {
    		$term = $interid;
                    $taxoname = $taxoname;
    		}
    		else {
    		$term = "";
    		}

    Then changed this if else statement in slider.php:

    if(($slider_type==1) || ($slider_type==3)) {
    	$allinfos = slider_getinfo_by_cat($slider_cat_id,$slider_view_number,$slider_fetch,$slider_title_max_char,$slider_title_thumb_max_char,$slider_desc_max_char);
    	}
    	else {
    	$allinfos = slider_getpages($slider_cat_id,$slider_view_number,$slider_title_max_char,$slider_title_thumb_max_char,$slider_desc_max_char);
    	}

    to:

    if($taxoname!=null && $taxoname!=""){
    $allinfos = slider_getinfo_by_term($taxoname,$term, $slider_view_number,$slider_title_max_char,$slider_title_thumb_max_char,$slider_desc_max_char);
    }
    elseif (($slider_type==1) || ($slider_type==3))  {
    	$allinfos = slider_getinfo_by_cat($slider_cat_id,$slider_view_number,$slider_fetch,$slider_title_max_char,$slider_title_thumb_max_char,$slider_desc_max_char);
    	}else{
    	$allinfos = slider_getpages($slider_cat_id,$slider_view_number,$slider_title_max_char,$slider_title_thumb_max_char,$slider_desc_max_char);
    }

    It seems to have worked for me – Just posting it if anyone finds it helpful!

    Thanks again for a great plugin!

  • The topic ‘UnPointZero Slider Custom Taxonomies Shortcode issue’ is closed to new replies.