Last active
January 14, 2016 02:55
-
-
Save katlove/02672ea86d82d3cf9fcc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Adding additional options in Genesis Theme Settings page for gathering a comma sep list of excluded categories | |
* Thanks to @author Bill Erickson for the jumping off point! | |
* @link http://www.billerickson.net/genesis-theme-options/ | |
* @package yourthemenamehere | |
*/ | |
/** | |
* Step 1: Register Defaults | |
* @param array $defaults | |
* @return array modified defaults | |
*/ | |
function kl_options_defaults( $defaults ) { | |
$defaults['exclude_categories'] = ''; | |
return $defaults; | |
} | |
add_filter( 'genesis_theme_settings_defaults', 'kl_options_defaults' ); | |
/** | |
* Step 2: Sanitization | |
* Register our option values with the no_html sanitization type defined within Genesis. | |
*/ | |
function kl_register_option_sanitization_filters() { | |
genesis_add_option_filter( | |
'no_html', | |
GENESIS_SETTINGS_FIELD, | |
array( | |
'exclude_categories', | |
) | |
); | |
} | |
add_action( 'genesis_settings_sanitizer_init', 'kl_register_option_sanitization_filters' ); | |
/** | |
* Step 3: Register additional metaboxes to Genesis > Theme Settings | |
* @param string $_genesis_theme_settings_pagehook | |
*/ | |
function kl_register_option_settings_box( $_genesis_theme_settings_pagehook ) { | |
add_meta_box( 'kl-option-settings', 'Exclude Categories', 'kl_option_settings_box', $_genesis_theme_settings_pagehook, 'main', 'high' ); | |
} | |
add_action( 'genesis_theme_settings_metaboxes', 'kl_register_option_settings_box' ); | |
/** | |
* Step 4: Option Settings Metabox Callback | |
* @see vg_register_option_settings_box() | |
*/ | |
function kl_option_settings_box() { | |
?> | |
<p><?php _e( 'Exclude these categories from the main post loop (Comma separated - 1,2,3 for example):', 'jharrison' );?><br /> | |
<input type="text" name="<?php echo GENESIS_SETTINGS_FIELD; ?>[exclude_categories]" value="<?php echo genesis_get_option('exclude_categories'); ?>" size="50" /> </p> | |
<?php | |
} | |
/** | |
* Remove Metabox for the blog page template from the options page | |
* because we prefer users to use the one above | |
* This removes unused or unneeded metaboxes from Genesis > Theme Settings. | |
* See /genesis/lib/admin/theme-settings for all metaboxes. | |
* | |
* And another thanks to @author Bill Erickson | |
* @link http://www.billerickson.net/code/remove-metaboxes-from-genesis-theme-settings/ | |
*/ | |
function be_remove_metaboxes( $_genesis_theme_settings_pagehook ) { | |
remove_meta_box( 'genesis-theme-settings-blogpage', $_genesis_theme_settings_pagehook, 'main' ); | |
} | |
add_action( 'genesis_theme_settings_metaboxes', 'be_remove_metaboxes' ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Include theme options | |
// UPDATE THIS TO THE CORRECT DIRECTORY! | |
require get_stylesheet_directory() . '/inc/functions-theme-opt.php'; | |
/* | |
* Add functionality to exclude categories to the metabox added to theme settings | |
* Box added to theme settings in /inc/functions-theme-opt.php' | |
*/ | |
function kl_exclude_categories_from_loop($query ) { | |
if( $query->is_main_query() && $query->is_home() ) { | |
$query->set( 'category__not_in', genesis_get_option( 'exclude_categories' ) ); | |
} | |
} | |
add_action( 'pre_get_posts', 'kl_exclude_categories_from_loop' ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment