Created
December 12, 2011 19:31
-
-
Save GaryJones/1468704 to your computer and use it in GitHub Desktop.
Amend behaviour on a Genesis Content Archives select setting toggle, to also show the related content limit setting when a different option is chosen.
This file contains hidden or 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
jQuery(function ($) { | |
// Remove default Genesis behaviour for this select element. | |
// If Genesis switches to using on() instead of live(), replace with a similar call | |
// to off() instead of die(). The genesis event namespace only added in Genesis 1.8.0 | |
$('#genesis-settings\\[content_archive\\]').die('change.genesis'); | |
// Add in our behaviour, using multiple namespaces to try and play nicely with others | |
$('#genesis-theme-settings-posts').on('change.genesis.my_theme_or_plugin', '#genesis-settings\\[content_archive\\]', my_theme_or_plugin.toggle_settings); | |
}); | |
// Create the function in an object variable to namespace it. | |
var my_theme_or_plugin = { | |
toggle_settings: function (element) { | |
// Cache the limit setting selector, and the chosen option value | |
var $limit_setting = jQuery('#genesis_content_limit_setting'), | |
setting_value = jQuery(element.target).val(); | |
// Show the limit setting when needed for our value AND the Genesis value. | |
if ('my-new-value' === setting_value || 'full' === setting_value) { | |
$limit_setting.slideDown('fast'); | |
} else { | |
$limit_setting.slideUp('fast'); | |
} | |
} | |
} |
This file contains hidden or 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 | |
add_filter( 'genesis_archive_display_options', 'my_theme_or_plugin_add_content_archive_display_option' ); | |
/** | |
* Adds new option to display type in Genesis Theme Settings Content Archives box. | |
* | |
* @since 1.0.0 | |
* | |
* @param array $options Existing display types. | |
* @return array Amended display types. | |
*/ | |
function my_theme_or_plugin_add_content_archive_display_option( $options ) { | |
$options['my-new-value'] = __( 'Display X then Y and Z', 'my-theme-or-plugin-domain' ); | |
return $options; | |
} | |
// Remember to add a function that enqueues the admin script for this page! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment