Changeset 429287
- Timestamp:
- 08/27/2011 01:08:31 AM (15 years ago)
- Location:
- sticky-custom-post-types/trunk
- Files:
-
- 2 edited
-
readme.txt (modified) (3 diffs)
-
sticky-custom-post-types.php (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sticky-custom-post-types/trunk/readme.txt
r426819 r429287 7 7 Stable tag: trunk 8 8 9 Enables a sticky checkbox on the custom post type add/edit page which will allow the user to stick custom post type entries to the front page.9 Enables support for sticky custom post types. 10 10 11 11 == Description == 12 12 13 This plugin enables sticky post support on custom post types by adding a "Stick this to the front page" checkbox on the admin add/editpage of selected custom post types.13 This plugin adds a "Stick this to the front page" checkbox on the admin add/edit entry page of selected custom post types. 14 14 15 Set custom post types to enable in Settings → Writing. 15 Set options to enable in Settings → Reading. Unless you're using custom queries to display your sticky posts, you probably want to check the option to add selected post types to the blog home. 16 17 Note: Sticky custom posts are stored in the global 'sticky_posts' option field, just like regular sticky posts. 16 18 17 19 == Installation == … … 19 21 1. Upload `sticky-custom-post-types.php` to the `/wp-content/plugins/` directory. 20 22 2. Activate the plugin through the 'Plugins' menu in WordPress. 21 3. Navigate to 'Settings → Writing' and select custom post types to enable.23 3. Navigate to 'Settings → Reading' and set your options. 22 24 23 25 == Frequently Asked Questions == … … 31 33 == Changelog == 32 34 35 = 1.2 = 36 * Modified filter method to control display of selected custom post types on the blog home, and added an option to allow the user to enable/disable the filter. 37 * Moved plugin settings from 'Settings → Writing' to 'Settings → Reading'. 38 33 39 = 1.1 = 34 40 * Moved plugin settings from 'Settings → General' to 'Settings → Writing'. -
sticky-custom-post-types/trunk/sticky-custom-post-types.php
r426804 r429287 3 3 Plugin Name: Sticky Custom Post Types 4 4 Plugin URI: http://superann.com/sticky-custom-post-types/ 5 Description: Enables a sticky checkbox on the admin add/edit page of custom post types which will allow the user to stick custom post type entries to the front page. Select custom post types in Settings → Writing.6 Version: 1. 15 Description: Enables support for sticky custom post types. Set options in Settings → Reading. 6 Version: 1.2 7 7 Author: Ann Oyama 8 8 Author URI: http://superann.com … … 27 27 28 28 function super_sticky_description() { 29 echo '<p>'.__('Enable s elected custom post types to stick to the front page.').'</p>';29 echo '<p>'.__('Enable support for sticky custom post types.').'</p>'; 30 30 } 31 31 32 function super_sticky_set tings() {32 function super_sticky_set_post_types() { 33 33 $post_types = get_post_types(array('_builtin' => false, 'public' => true), 'names'); 34 34 if(!empty($post_types)) { 35 $checked_post_types = super_sticky_ get();35 $checked_post_types = super_sticky_post_types(); 36 36 foreach($post_types as $post_type) { ?> 37 < span><input type="checkbox" id="post_type_<?php echo $post_type; ?>" name="sticky_custom_post_types[]" value="<?php echo $post_type; ?>" <?php checked(in_array($post_type, $checked_post_types)); ?> /> <label for="post_type_<?php echo $post_type; ?>"><?php echo $post_type; ?></label></span><br/><?php37 <div><input type="checkbox" id="post_type_<?php echo $post_type; ?>" name="sticky_custom_post_types[]" value="<?php echo $post_type; ?>" <?php checked(in_array($post_type, $checked_post_types)); ?> /> <label for="post_type_<?php echo $post_type; ?>"><?php echo $post_type; ?></label></div><?php 38 38 } 39 39 } … … 42 42 } 43 43 44 function super_sticky_filter($query_type) { 45 $filters = get_option('sticky_custom_post_types_filters'); 46 if(!is_array($filters)) $filters = array(); 47 return in_array($query_type, $filters); 48 } 49 50 function super_sticky_set_filters() { ?> 51 <span><input type="checkbox" id="sticky_custom_post_types_filters_home" name="sticky_custom_post_types_filters[]" value="home" <?php checked(super_sticky_filter('home')); ?> /> <label for="sticky_custom_post_types_filters_home">home page</label></span><?php 52 } 53 44 54 function super_sticky_admin_init() { 45 register_setting('writing', 'sticky_custom_post_types'); 46 add_settings_section('super_sticky_options', 'Sticky Custom Post Types', 'super_sticky_description', 'writing'); 47 add_settings_field('sticky_custom_post_types', 'Custom Post Types', 'super_sticky_settings', 'writing', 'super_sticky_options'); 55 register_setting('reading', 'sticky_custom_post_types'); 56 register_setting('reading', 'sticky_custom_post_types_filters'); 57 add_settings_section('super_sticky_options', 'Sticky Custom Post Types', 'super_sticky_description', 'reading'); 58 add_settings_field('sticky_custom_post_types', 'Show "Stick this..." checkbox on', 'super_sticky_set_post_types', 'reading', 'super_sticky_options'); 59 add_settings_field('sticky_custom_post_types_filters', 'Display selected post type(s) on', 'super_sticky_set_filters', 'reading', 'super_sticky_options'); 48 60 } 49 61 50 62 add_action('admin_init', 'super_sticky_admin_init', 20); 51 63 52 function super_sticky_ get($posts=FALSE) {64 function super_sticky_post_types($posts=false) { 53 65 $post_types = get_option('sticky_custom_post_types'); 54 66 if(!is_array($post_types)) … … 59 71 } 60 72 61 function super_sticky_meta() { ?>73 function super_sticky_meta() { global $post; ?> 62 74 <input id="super-sticky" name="sticky" type="checkbox" value="sticky" <?php checked(is_sticky($post->ID)); ?> /> <label for="super-sticky" class="selectit"><?php _e('Stick this to the front page') ?></label><?php 63 75 } 64 76 65 77 function super_sticky_add_meta_box() { 66 foreach(super_sticky_ get() as $post_type)78 foreach(super_sticky_post_types() as $post_type) 67 79 if(current_user_can('edit_others_posts')) 68 80 add_meta_box('super_sticky_meta', 'Sticky', 'super_sticky_meta', $post_type, 'side', 'high'); … … 71 83 add_action('admin_init', 'super_sticky_add_meta_box'); 72 84 73 function super_sticky_posts($query) { 74 if(is_home() && (false === $query->query_vars['suppress_filters'])) 75 $query->set('post_type', super_sticky_get(TRUE)); 85 function super_sticky_posts_filter($query) { 86 if($query->is_home && !$query->is_paged) 87 if(super_sticky_filter('home')) 88 $query->set('post_type', super_sticky_post_types(true)); 89 else 90 $query->set('post_type', 'post'); 76 91 return $query; 77 92 } 78 93 79 add_filter('pre_get_posts', 'super_sticky_posts ');94 add_filter('pre_get_posts', 'super_sticky_posts_filter'); 80 95 ?>
Note: See TracChangeset
for help on using the changeset viewer.