Changeset 359355
- Timestamp:
- 03/12/2011 09:51:36 PM (15 years ago)
- Location:
- no-sub-category-posts-in-loop
- Files:
-
- 4 edited
- 1 copied
-
tags/0.4 (copied) (copied from no-sub-category-posts-in-loop/trunk)
-
tags/0.4/ft-no-subcats-in-loop.php (modified) (4 diffs)
-
tags/0.4/readme.txt (modified) (3 diffs)
-
trunk/ft-no-subcats-in-loop.php (modified) (4 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
no-sub-category-posts-in-loop/tags/0.4/ft-no-subcats-in-loop.php
r93181 r359355 1 1 <?php 2 /** 3 * Removes subcategory posts from category arhcives 4 * 5 * @package No_Sub_Category_Posts_In_Loop 6 * @version 0.4 2 7 /* 3 8 Plugin Name: No Sub-Category Posts in Loop 4 9 Plugin URI: http://fullthrottledevelopment.com/no-sub-category-posts-in-loop/ 5 10 Description: This plugin allows you to only display post from the current category in your loop (no posts from sub cats) 6 Version: 0. 311 Version: 0.4 7 12 Author: FullThrottle Development 8 13 Author URI: http://fullthrottledevelopment.com/ 9 14 */ 10 15 11 // Primary Developer : Glenn Ansley (http://glennansley.com)16 // Primary Developer : Glenn Ansley (http://glennansley.com) 12 17 13 / *Copyright 2009 Glenn Ansley18 // Copyright 2009-2011 Glenn Ansley. GPL 14 19 15 20 /* Release History 21 0.4 - Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built. 16 22 0.3 - Modified directory structure so that plugin may be added and activated from wp-admin 17 23 0.2 - Forgot to define a global, preventing posts from appearing that should. (thanks to http://redfootwebdesign.com for the heads up!) … … 19 25 */ 20 26 21 define( 'FT_NSCP_Version' , '0.3' ); 27 /** 28 * Constant holding the version number 29 * @since 0.1 30 */ 31 define( 'FT_NSCP_Version' , '0.4' ); 22 32 23 / / Define plugin path24 if ( !defined('WP_CONTENT_DIR') ) { 25 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content'); 26 } 33 /** 34 * Constant holding the plugin directory path 35 * @since 0.1 36 */ 27 37 define('FT_NSCP_PATH' , WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__)) ); 28 38 29 // Define plugin URL 30 if ( !defined('WP_CONTENT_URL') ) { 31 define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content' ); 32 } 39 /** 40 * Constant holding the plugin directory URL 41 */ 33 42 define( 'FT_NSCP_URL' , WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)) ); 34 43 … … 45 54 } 46 55 56 /** 57 * Filter's the query's where clause 58 59 * @param str incoming WHERE clause 60 * @global $wp_query WordPress query object 61 * @global $wpdb WordPress database access object 62 * @global $wp_version WordPress version number 63 * @retuns str Modified or original WHERE clause 64 * @since 0.1 65 */ 47 66 function ft_nscp_mod_where( $where ){ 48 global $wp_query, $wpdb;67 global $wp_query, $wpdb, $wp_version; 49 68 50 69 // Fire off if we're viewing a category archive … … 52 71 53 72 // Get children categories of current cat if they exist 54 if ( $excludes = get_categories( "child_of=".$wp_query->get('cat')) ){73 if ( $excludes = get_categories( "child_of=" . $wp_query->get( 'cat' ) ) ) { 55 74 56 75 // For each child, add just the ID to an array 57 foreach ( $excludes as $key => $value ){ 76 foreach ( $excludes as $key => $value ) { 77 58 78 $exs[] = $value->cat_ID; 79 59 80 } 81 60 82 } 61 83 62 84 // If array exists, remove posts in child categories from query. 63 if ( isset($exs) && is_array($exs) ){ 64 $where .= " AND ".$wpdb->prefix."term_taxonomy.term_id NOT IN (".implode(",",$exs).") "; 85 if ( isset( $exs ) && is_array( $exs ) ) { 86 87 // WP Query changed in 3.1 88 if ( version_compare( $wp_version, 3.1, '<' ) ) 89 $where .= " AND " . $wpdb->prefix . "term_taxonomy.term_id NOT IN ( ". implode( ",", $exs ) . " ) "; 90 else 91 $where .= " AND " . $wpdb->prefix . "term_relationships.term_taxonomy_id NOT IN ( ". implode( ",", $exs ) . " ) "; 92 65 93 } 66 94 } 67 95 68 96 return $where; 97 69 98 } 70 99 71 if ( !is_admin() ){ 72 add_action('posts_where','ft_nscp_mod_where'); 100 /** 101 * Removes the filter after the main query has been built to not interfere with widgets 102 * 103 * @since 0.4 104 */ 105 function ft_nscp_remove_filter() { 106 107 remove_filter( 'posts_where', 'ft_nscp_mod_where' ); 108 73 109 } 110 111 if ( ! is_admin() ) { 112 113 add_filter( 'posts_where', 'ft_nscp_mod_where' ); 114 add_action( 'template_redirect', 'ft_nscp_remove_filter' ); 115 116 } 117 118 /** 119 * Adds ability to donate to plugin development 120 * 121 * @since 0.4 122 */ 123 function ft_ncsp_donate() { 124 125 // Kill notice 126 if ( isset( $_GET['remove_ncsp_donate'] ) ) 127 update_option( 'ft_ncsp_show_donate', '0.4' ); 128 129 // Look for wp_option 130 if ( ! $show_donation_link = get_option( 'ft_ncsp_show_donate' ) ) { 131 update_option( 'ft_nscp_show_donate', 'yes' ); 132 $show_donation_link = 'yes'; 133 } 134 135 if ( 'yes' == $show_donation_link ) 136 add_action( 'admin_notices', 'ft_ncsp_donate_notice' ); 137 138 } 139 add_action( 'admin_init', 'ft_ncsp_donate' ); 140 141 /** 142 * This displays the option to donate via paypal 143 * 144 * @since 0.4 145 */ 146 function ft_ncsp_donate_notice() { 147 148 $paypal_link = 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MD85KZY5SAYLA'; 149 $no_thanks = esc_url( admin_url( 'plugins.php?remove_ncsp_donate=true' ) ); 150 echo "<div class='update-nag'>" . sprintf( __( "Thanks for upgrading the 'No subcats in loops' plugin. Would you consider sending the developer $5.00 USD to sustain development? <a href='%s'>Yes, take me to PayPal</a> | <a href='%s'>No thanks</a> | <a href='%s'>I already did</a>." ), $paypal_link, $no_thanks, $no_thanks ) . "</div>"; 151 152 } -
no-sub-category-posts-in-loop/tags/0.4/readme.txt
r116455 r359355 4 4 Tags: loop, categories, cats, posts 5 5 Requires at least: 2.7 6 Tested up to: 2.7.17 Stable tag: 0. 36 Tested up to: 3.1 7 Stable tag: 0.4 8 8 9 9 Once activated, only posts from the current category are displayed in your loop (no posts from sub cats). … … 14 14 That's all it does. No options. If you find you need options, let me know and I'll build them into it. 15 15 16 = Version History = 16 As of 0.4 I remove the filter after the main query is built so that it doesn't interfere with widgets. 17 If you have a custom query or call wp_query on a category archive template, you'll need to add and remove the filters before and after your query. Below is an example of how to do this if you use wp_query. Again, this is not necessary unless you have modified queries in a template file. 17 18 19 ` 20 add_filter( 'posts_where', 'ft_nscp_mod_where' ); 21 query_posts( array( 'your-custom' => 'args' ) ); 22 remove_filter( 'posts_where', 'ft_nscp_mod_where' ); 23 ` 24 25 Its important that you remove what you add. 26 27 == Changelog == 28 29 * 0.4 - Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built. 18 30 * 0.3 - Modified directory structure so that plugin may be added and activated from wp-admin 19 31 * 0.2 - Forgot to define a global, preventing posts from appearing that should. (thanks to http://redfootwebdesign.com for the heads up!) … … 30 42 31 43 http://fullthrottledevelopment.com/no-sub-category-posts-in-loop 44 45 == Upgrade Notice == 46 Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built. -
no-sub-category-posts-in-loop/trunk/ft-no-subcats-in-loop.php
r93181 r359355 1 1 <?php 2 /** 3 * Removes subcategory posts from category arhcives 4 * 5 * @package No_Sub_Category_Posts_In_Loop 6 * @version 0.4 2 7 /* 3 8 Plugin Name: No Sub-Category Posts in Loop 4 9 Plugin URI: http://fullthrottledevelopment.com/no-sub-category-posts-in-loop/ 5 10 Description: This plugin allows you to only display post from the current category in your loop (no posts from sub cats) 6 Version: 0. 311 Version: 0.4 7 12 Author: FullThrottle Development 8 13 Author URI: http://fullthrottledevelopment.com/ 9 14 */ 10 15 11 // Primary Developer : Glenn Ansley (http://glennansley.com)16 // Primary Developer : Glenn Ansley (http://glennansley.com) 12 17 13 / *Copyright 2009 Glenn Ansley18 // Copyright 2009-2011 Glenn Ansley. GPL 14 19 15 20 /* Release History 21 0.4 - Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built. 16 22 0.3 - Modified directory structure so that plugin may be added and activated from wp-admin 17 23 0.2 - Forgot to define a global, preventing posts from appearing that should. (thanks to http://redfootwebdesign.com for the heads up!) … … 19 25 */ 20 26 21 define( 'FT_NSCP_Version' , '0.3' ); 27 /** 28 * Constant holding the version number 29 * @since 0.1 30 */ 31 define( 'FT_NSCP_Version' , '0.4' ); 22 32 23 / / Define plugin path24 if ( !defined('WP_CONTENT_DIR') ) { 25 define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content'); 26 } 33 /** 34 * Constant holding the plugin directory path 35 * @since 0.1 36 */ 27 37 define('FT_NSCP_PATH' , WP_CONTENT_DIR.'/plugins/'.plugin_basename(dirname(__FILE__)) ); 28 38 29 // Define plugin URL 30 if ( !defined('WP_CONTENT_URL') ) { 31 define( 'WP_CONTENT_URL', get_option('siteurl') . '/wp-content' ); 32 } 39 /** 40 * Constant holding the plugin directory URL 41 */ 33 42 define( 'FT_NSCP_URL' , WP_CONTENT_URL.'/plugins/'.plugin_basename(dirname(__FILE__)) ); 34 43 … … 45 54 } 46 55 56 /** 57 * Filter's the query's where clause 58 59 * @param str incoming WHERE clause 60 * @global $wp_query WordPress query object 61 * @global $wpdb WordPress database access object 62 * @global $wp_version WordPress version number 63 * @retuns str Modified or original WHERE clause 64 * @since 0.1 65 */ 47 66 function ft_nscp_mod_where( $where ){ 48 global $wp_query, $wpdb;67 global $wp_query, $wpdb, $wp_version; 49 68 50 69 // Fire off if we're viewing a category archive … … 52 71 53 72 // Get children categories of current cat if they exist 54 if ( $excludes = get_categories( "child_of=".$wp_query->get('cat')) ){73 if ( $excludes = get_categories( "child_of=" . $wp_query->get( 'cat' ) ) ) { 55 74 56 75 // For each child, add just the ID to an array 57 foreach ( $excludes as $key => $value ){ 76 foreach ( $excludes as $key => $value ) { 77 58 78 $exs[] = $value->cat_ID; 79 59 80 } 81 60 82 } 61 83 62 84 // If array exists, remove posts in child categories from query. 63 if ( isset($exs) && is_array($exs) ){ 64 $where .= " AND ".$wpdb->prefix."term_taxonomy.term_id NOT IN (".implode(",",$exs).") "; 85 if ( isset( $exs ) && is_array( $exs ) ) { 86 87 // WP Query changed in 3.1 88 if ( version_compare( $wp_version, 3.1, '<' ) ) 89 $where .= " AND " . $wpdb->prefix . "term_taxonomy.term_id NOT IN ( ". implode( ",", $exs ) . " ) "; 90 else 91 $where .= " AND " . $wpdb->prefix . "term_relationships.term_taxonomy_id NOT IN ( ". implode( ",", $exs ) . " ) "; 92 65 93 } 66 94 } 67 95 68 96 return $where; 97 69 98 } 70 99 71 if ( !is_admin() ){ 72 add_action('posts_where','ft_nscp_mod_where'); 100 /** 101 * Removes the filter after the main query has been built to not interfere with widgets 102 * 103 * @since 0.4 104 */ 105 function ft_nscp_remove_filter() { 106 107 remove_filter( 'posts_where', 'ft_nscp_mod_where' ); 108 73 109 } 110 111 if ( ! is_admin() ) { 112 113 add_filter( 'posts_where', 'ft_nscp_mod_where' ); 114 add_action( 'template_redirect', 'ft_nscp_remove_filter' ); 115 116 } 117 118 /** 119 * Adds ability to donate to plugin development 120 * 121 * @since 0.4 122 */ 123 function ft_ncsp_donate() { 124 125 // Kill notice 126 if ( isset( $_GET['remove_ncsp_donate'] ) ) 127 update_option( 'ft_ncsp_show_donate', '0.4' ); 128 129 // Look for wp_option 130 if ( ! $show_donation_link = get_option( 'ft_ncsp_show_donate' ) ) { 131 update_option( 'ft_nscp_show_donate', 'yes' ); 132 $show_donation_link = 'yes'; 133 } 134 135 if ( 'yes' == $show_donation_link ) 136 add_action( 'admin_notices', 'ft_ncsp_donate_notice' ); 137 138 } 139 add_action( 'admin_init', 'ft_ncsp_donate' ); 140 141 /** 142 * This displays the option to donate via paypal 143 * 144 * @since 0.4 145 */ 146 function ft_ncsp_donate_notice() { 147 148 $paypal_link = 'https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=MD85KZY5SAYLA'; 149 $no_thanks = esc_url( admin_url( 'plugins.php?remove_ncsp_donate=true' ) ); 150 echo "<div class='update-nag'>" . sprintf( __( "Thanks for upgrading the 'No subcats in loops' plugin. Would you consider sending the developer $5.00 USD to sustain development? <a href='%s'>Yes, take me to PayPal</a> | <a href='%s'>No thanks</a> | <a href='%s'>I already did</a>." ), $paypal_link, $no_thanks, $no_thanks ) . "</div>"; 151 152 } -
no-sub-category-posts-in-loop/trunk/readme.txt
r116455 r359355 4 4 Tags: loop, categories, cats, posts 5 5 Requires at least: 2.7 6 Tested up to: 2.7.17 Stable tag: 0. 36 Tested up to: 3.1 7 Stable tag: 0.4 8 8 9 9 Once activated, only posts from the current category are displayed in your loop (no posts from sub cats). … … 14 14 That's all it does. No options. If you find you need options, let me know and I'll build them into it. 15 15 16 = Version History = 16 As of 0.4 I remove the filter after the main query is built so that it doesn't interfere with widgets. 17 If you have a custom query or call wp_query on a category archive template, you'll need to add and remove the filters before and after your query. Below is an example of how to do this if you use wp_query. Again, this is not necessary unless you have modified queries in a template file. 17 18 19 ` 20 add_filter( 'posts_where', 'ft_nscp_mod_where' ); 21 query_posts( array( 'your-custom' => 'args' ) ); 22 remove_filter( 'posts_where', 'ft_nscp_mod_where' ); 23 ` 24 25 Its important that you remove what you add. 26 27 == Changelog == 28 29 * 0.4 - Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built. 18 30 * 0.3 - Modified directory structure so that plugin may be added and activated from wp-admin 19 31 * 0.2 - Forgot to define a global, preventing posts from appearing that should. (thanks to http://redfootwebdesign.com for the heads up!) … … 30 42 31 43 http://fullthrottledevelopment.com/no-sub-category-posts-in-loop 44 45 == Upgrade Notice == 46 Fixed bug introduced with WordPress 3.1. Added inline docs. Removed filter after main query is built.
Note: See TracChangeset
for help on using the changeset viewer.