[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 = ""; $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); } } // Smart Index // one of the tags of the current post must be included in the posts tags of the index if($params["smart_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 : https://codex.www.ads-software.com/Function_Reference/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 } endwhile; } }// 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); } wp_reset_query(); return $results; }
https://www.ads-software.com/extend/plugins/post-category-index-generator/
Viewing 3 replies - 1 through 3 (of 3 total)
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.