Changeset 2071541
- Timestamp:
- 04/19/2019 08:21:28 PM (7 years ago)
- Location:
- specify-home-hidden-categories/trunk
- Files:
-
- 2 edited
-
index.php (modified) (3 diffs)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
specify-home-hidden-categories/trunk/index.php
r1903973 r2071541 3 3 Plugin Name: Specify Home Hidden Categories 4 4 Description: Specify the Homepage&RSS hidden under all the article 5 Plugin URI: http ://www.9sep.org/specify-home-hidden-categories6 Version: 0.2. 15 Plugin URI: https://www.9sep.org/specify-home-hidden-categories 6 Version: 0.2.2 7 7 Author: Zhys 8 Author URI: http ://www.9sep.org/author/zhys8 Author URI: https://www.9sep.org/author/zhys 9 9 License: GPLv2 or later 10 10 … … 21 21 along with this program; if not, write to the Free Software 22 22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 23 */24 defined( 'ABSPATH') OR exit;25 add_action( 'admin_init', 'specify_homepage_cats_init');23 */ 24 defined('ABSPATH') OR exit; 25 add_action('admin_init', 'specify_homepage_cats_init'); 26 26 add_filter('pre_get_posts', 'specifycats'); 27 27 28 function specify_homepage_cats_init() {29 if (get_bloginfo('language')=='zh-CN'||get_bloginfo('language')=='zh-TW'){30 $specify_tips='指定首页隐藏分类';31 }else{32 $specify_tips='Specify Categories';33 }28 function specify_homepage_cats_init() { 29 if (get_bloginfo('language') == 'zh-CN' || get_bloginfo('language') == 'zh-TW') { 30 $specify_tips = '指定首页隐藏分类'; 31 } else { 32 $specify_tips = 'Specify Categories'; 33 } 34 34 add_settings_field( 35 35 'specify_cats', … … 39 39 'default' 40 40 ); 41 register_setting( 'reading', 'specify_cats');41 register_setting('reading', 'specify_cats'); 42 42 } 43 43 44 function specify_homepage_cats_callback_function() {45 $options= get_option('specify_cats');46 $pag= 'specify_cats';47 $_cats = get_terms( 'category');48 $html= '';44 function specify_homepage_cats_callback_function() { 45 $options = get_option('specify_cats'); 46 $pag = 'specify_cats'; 47 $_cats = get_terms('category'); 48 $html = ''; 49 49 50 foreach ($_cats as $term){51 if($options != ''){52 $checked = in_array($term->term_id, $options) ? 'checked="checked"' : '';53 }50 foreach ($_cats as $term) { 51 if ($options != '') { 52 $checked = in_array($term->term_id, $options) ? 'checked="checked"' : ''; 53 } 54 54 55 $html .= '<p class="sep9_l">';56 $html .= sprintf( '<input type="checkbox" id="%1$s[%2$s]" name="%1$s[]" value="%2$s" %3$s />', $pag, $term->term_id, $checked);57 $html .= sprintf( '<label for="%1$s[%3$s]"> %2$s</label><br>', $pag, $term->name, $term->term_id);58 $html .= '</p>';59 }55 $html .= '<p class="sep9_l">'; 56 $html .= sprintf('<input type="checkbox" id="%1$s[%2$s]" name="%1$s[]" value="%2$s" %3$s />', $pag, $term->term_id, $checked); 57 $html .= sprintf('<label for="%1$s[%3$s]"> %2$s</label><br>', $pag, $term->name, $term->term_id); 58 $html .= '</p>'; 59 } 60 60 61 $html .= '<p class="sep"></p>';61 $html .= '<p class="sep"></p>'; 62 62 63 echo $html;63 echo $html; 64 64 } 65 65 66 function getchild($id) {67 $result = explode('/', get_category_children($id));66 function getchild($id) { 67 $result = explode('/', get_category_children($id)); 68 68 $childs = array(); 69 foreach($result as $i){ 70 if(!empty($i))$childs[] = get_category($i); 69 foreach ($result as $i) { 70 if (!empty($i)) { 71 $childs[] = get_category($i); 72 } 73 71 74 } 72 75 return $childs; 73 76 } 74 77 75 function array_get_by_key(array $array, $string){ 76 if (!trim($string)) return false; 77 preg_match_all("/\"$string\";\w{1}:(?:\d+:|)(.*?);/", serialize($array), $res); 78 return $res[1]; 78 function array_get_by_key(array $array, $string) { 79 if (!trim($string)) { 80 return false; 81 } 82 83 preg_match_all("/\"$string\";\w{1}:(?:\d+:|)(.*?);/", serialize($array), $res); 84 return $res[1]; 79 85 } 80 86 81 function hidecats($catID){ 82 $cata=array(); 83 foreach($catID as $i){ 84 if(!empty($i))$cata[] = get_category($i); 85 if(get_category_children($i)!=""){ 86 $cata[]=getchild($i); 87 }else{ 88 $cata[]=$i; 87 function hidecats($catID) { 88 $cata = array(); 89 foreach ($catID as $i) { 90 if (!empty($i)) { 91 $cata[] = get_category($i); 92 } 93 94 if (get_category_children($i) != "") { 95 $cata[] = getchild($i); 96 } else { 97 $cata[] = $i; 89 98 } 90 99 } 91 return array_unique(array_get_by_key($cata, 'term_id'));100 return array_unique(array_get_by_key($cata, 'term_id')); 92 101 } 93 102 94 function specifycats($query) {95 if ( $query->is_home || $query->is_feed) {103 function specifycats($query) { 104 if ($query->is_home || $query->is_feed) { 96 105 $query->set('category__not_in', hidecats(get_option('specify_cats'))); 97 106 } 98 107 return $query; 99 108 } 100 101 -
specify-home-hidden-categories/trunk/readme.txt
r1903973 r2071541 2 2 Contributors: yzhs 3 3 Tags: SHHC,Specify,exclude,hide,related,HiddenCategories,Specify Home Hidden,categories,Cat,options,Homepage,Home,feed,rss,get_posts,have_posts,the_post,Hidden,page,post,Posts,All,首页隐藏特定分类,首页排除指定文章不显示,隐藏分类,隐藏文章,隐藏指定分类目录文章 4 Donate link: http ://www.9sep.org/specify-home-hidden-categories5 Stable tag: 0.2. 14 Donate link: https://www.9sep.org/specify-home-hidden-categories 5 Stable tag: 0.2.2 6 6 Requires at least: 3.5 7 Tested up to: 4.9.67 Tested up to: 5.1.1 8 8 License: GPLv2 or later 9 9 … … 38 38 English: author/[zhys](http://www.9sep.org/author/zhys) English is so bad, you can help me with a simple question-and-answer feature, please? 39 39 40 中文:[Specify Home Hidden Categories常见问题回答](http ://www.9sep.org/specify-home-hidden-categories#comments)40 中文:[Specify Home Hidden Categories常见问题回答](https://www.9sep.org/specify-home-hidden-categories#comments) 41 41 42 42 == Changelog == … … 53 53 * 中文:测试兼容性至WP 4.9.6,添加中文提示 54 54 55 = 0.2.2 = 56 * English: WordPress Tested up to: 5.1.1 57 * 中文:测试兼容性至WP 5.1.1 58 55 59 == Reviews == 56 60 * 中文: … … 63 67 64 68 == Upgrade Notice == 69 2019-04-20 00 Tested up to: 5.1.1 70 2018-07-04 20 Tested up to: 4.9.6 71 2015-07-27 14 Tested up to: 4.2.3 65 72 2015-01-16 16 Tested up to: 4.1 66 2015-07-27 14 Tested up to: 4.2.367 2018-07-04 20 Tested up to: 4.9.668 73
Note: See TracChangeset
for help on using the changeset viewer.