Support » Plugin: Post Category Index Generator » [Plugin: Post Category Index Generator] Smart Index Generator Widget

  • Did you ever consider to use “Post Category Index Generator” in combination with the “page in widget” plugin?

    If you make the Index Generator “listen” to tags in the current post, you can generate a “Smart Index Generator” of your posts (in a widget beside). Just change the code of the following function in “index.php”.

    [smart_index = true]

    (Please improve! I’m not a programmer!)

    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 = "";
    	if((is_array($sub_categories)) && $only_direct_descents){
    		foreach($sub_categories as $sub_category){
    		$exclude = implode(",",$subcategory_ids_to_exclude);
    		  $results = get_posts("cat=".$category_id.",".$exclude."&posts_per_page=999".$extra_param);
    	// Smart Index
    	// one of the tags of the current post must be included in the posts tags of the index
    		global $posts_incl;
    		global $post;
    		// 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) {
    			foreach($tag_ids as $tag_id){
    				// arguments for query_posts :
    				$args = array(
    						'tag__in' => array($tag_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();
    							$posts_incl = "posts_include"; // hide index if there are no posts
    			}// end foreach
    		$include = implode(",",$tag_posts_in_ids);
    		$results = get_posts("include=".$include.",posts_per_page=999".$extra_param);
    	// ende 
    		} else {
    			$results = query_posts("cat=".$category_id."&posts_per_page=999".$extra_param);
    	return $results;

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Marco Constancio


    First thank for that input. It is really good to see someone to use and trying to contribute to this plugin.

    As for your code, after thinking on how to best implement it, I came to the conclusion that there is no need to overcomplicate this ideia. Instead of adding code to make several queries to auto detect tags, I added 2 extra parameters (tags_or and tags_and) that allows a user too choose the tags that he wants to filter.

    I believe that this is the best aproach but if you don’t think so, feel free to add arguments how to improve and I will check it.

    Thank You Marco – this is a great idea! Maybe you can include the “page in widget” plugin in your “index generator” and add a widget to the plugin. I think this would be a great combination.

    It was not easy for me to hide the widget, when there is no post with the same tag. Therefor I hade to change the “page to widget” plugin a little bit…

    Plugin Author Marco Constancio


    While the both plugin might work great, page in widget is already a plugin on its own so I don’t think it is necessary to duplicate that functionality.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Plugin: Post Category Index Generator] Smart Index Generator Widget’ is closed to new replies.