WordPress.org

Ready to get started?Download WordPress

Forums

Post Category Index Generator
[resolved] New parameter: tag_and_cat (3 posts)

  1. peter1000
    Member
    Posted 1 year ago #

    I added a new paramenter [tag_and_cat=1]. It allows you to index only posts with their tags also included in the current post.

    Hop someone can improve the code (I am not a programmer). I made some changes to the following function in the index.php file of the plugin (for me it works):

    function pcig_get_category_posts($category_id,$params,$only_direct_descents=false){
    	$sub_categories = get_term_children($category_id,'category');
    	$subcategory_ids_to_exclude = array();
    	$exclude = "";
    	$extra_param="";
    
    	if($params["orderby"]){
    		$extra_param.="&orderby=".$params["orderby"];
    	}
    	if($params["order"]){
    		$extra_param.="&order=".$params["order"];
    	}
    
    	if((is_array($sub_categories)) && $only_direct_descents){
    		foreach($sub_categories as $sub_category){
    				$subcategory_ids_to_exclude[]=-$subcategory->term_id;
    		}
    		$exclude = implode(",",$subcategory_ids_to_exclude);
    
    		if(!empty($exclude)){
    
    			 $results = get_posts("cat=".$category_id.",".$exclude."&posts_per_page=999".$extra_param);
    		}
    	}else{
    
    		// tag_and_cat
    
    		if($params["tag_and_cat"]){
    			global $post;
    			$curr_id = $post->ID;
    			// Get current post tags
    			$tag_posts_in_ids = array();
    			$tag_ids = array();
    			$tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
    			if ($tag_ids) {
    				$first_tag = $tag_ids[0]; // we only need the id of first tag
    			 // echo "tag ". $first_tag;
    				// arguments for query_posts : http://codex.wordpress.org/Function_Reference/query_posts
    				$args = array(
    						'tag__in' => array($first_tag),
    						'category_in' => $category_in,
    						'post__not_in' => array($post->ID),
    						'showposts' => 1000, // these are the number of related posts we want to display
    						'ignore_sticky_posts' => 1 // to exclude the sticky post
    						);
    				// WP_Query takes the same arguments as query_posts
    				$related_query = new WP_Query($args);
    				if ($related_query->have_posts()) {
    						while ($related_query->have_posts()) : $related_query->the_post();
    						if (in_category($category_id, get_the_ID())) {
    							$tag_posts_in_ids[] = get_the_ID();
    							//echo "cat: ".$category_id." ID: ".get_the_ID()."  -  ";
    						}
    						endwhile;
    				}
    			}
    			$include = implode(",",$tag_posts_in_ids);
    			$results = get_posts('include='.$include."&posts_per_page=999".$extra_param);
    		// ende peter	
    
    		} else {
    
    			$results = query_posts("cat=".$category_id."&posts_per_page=999".$extra_param);
    		}
    	}
    	wp_reset_query();
    
    	return $results;
    }

    http://wordpress.org/extend/plugins/post-category-index-generator/

  2. peter1000
    Member
    Posted 1 year ago #

    Please delete/ forget this thread - go to Smart Index Generator!

  3. Boris_C
    Member
    Posted 1 year ago #

    Peter,

    where is the Smart Index Generator?

    Can't find it...

    Boris

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic