I modified your plugin to support post categories
-
Add Widget After Content plugin was missing the ability to filter based on categories (it initially only allowed filter based on post type and post format).
I have modified your plugin to support filtering based on categories.
Added this to the awac_initialize_options function after line 137 (in add-widget-after-content-admin.php):
add_settings_field( 'all_post_categories', __('Post Categories<p class="description">The widget will not show on post categories that are checked</p>', $this->plugin_name ), array($this, 'awac_postcategories_boxes_display'), 'awac-options', 'awac_basic' ); register_setting( 'awac_basic', 'all_post_categories' );
Then in the same file, at line 255, I added this new function:
/** * Display the categories for posts * */ public function awac_postcategories_boxes_display(){ $post_categories = get_categories(); $options = (array)get_option('all_post_categories'); foreach ( $post_categories as $category ) { $cat = $category->name; if( !isset($options[$cat]) ){ $options[$cat] = 0; } echo '<label><input name="all_post_categories['. $cat .']" id="all_post_categories['. $cat .']" type="checkbox" value="1" class="code" ' . checked( 1, $options[$cat], false ) . ' />'. $cat .'</label><br />' ; } }
Then in add-widget-after-content.php in show-awac function at line 134, I added this line:
$exclude_category = (array)get_option('all_post_categories');
And added this line at line 137 (same file, same function):
$category = get_the_category();
Then finally, at line 153 (in the same file and function), I added this code:
foreach ($category as $categories) { $cat = $categories->name; if(isset($exclude_category[$cat]) == 1){ return false; } return true; }
I didn’t add code for categories for meta functions, and I haven’t tested to determine whether that code will cause issues for if a post type/format is excluded. But it does the job. Hopefully the above changes will save you time and work in adding filtering based on categories in the next update so I don’t lose the feature I added to your plugin. 🙂
- The topic ‘I modified your plugin to support post categories’ is closed to new replies.