Last active
August 19, 2016 09:41
-
-
Save KinnaT/661c76fcbf66334323cf3de7834c4563 to your computer and use it in GitHub Desktop.
Functional selectable sliders as page meta option - accounts for the Revolution Slider and Smart Slider 3 plugins, trivial to add support for more plugins
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 | |
// | |
// Adding meta boxes for sliders to page options: | |
// | |
$config = array( | |
'title' => __('General Options', 'theme_admin'), | |
'group_id' => 'general', | |
'context' => 'normal', | |
'priority' => 'low', | |
'types' => array( 'page' ) | |
); | |
$options = array( | |
array( | |
'type' => 'on_off', | |
'id' => 'pageslider', | |
'toggle' => 'toggle-show-pageslider', | |
'title' => __('Show Image Slider', 'theme_admin'), | |
'description' => __('Turn on to enable an image slider at the top of the page', 'theme_admin'), | |
'default' => 'off', | |
), | |
array( | |
'type' => 'select', | |
'id' => 'pageslider_alias', | |
'toggle_group' => 'toggle-show-pageslider toggle-show-pageslider-on', | |
'title' => __('Choose Slider', 'theme_admin'), | |
'description' => __('Select the slider to use', 'theme_admin'), | |
'source' => array( | |
'pageslider' => true | |
) | |
) | |
); | |
new metaboxes_tool($config, $options); | |
// | |
// in input-tool.php: | |
// | |
class input_tool { | |
var $options; | |
var $config; | |
var $saved_data; | |
var $multi_counter = 0; | |
function input_tool( $options, $config ) { | |
$this->options = $options; | |
$this->config = $config; | |
} | |
function get_saved_theme_option() { | |
$groups = get_option( THEME_SLUG . '_options' ); | |
if( is_array($groups) ) { | |
foreach ( $groups as $group_key => $group ) { | |
if( is_array( $group ) ) { | |
foreach ( $group as $field_key => $field ) { | |
$options[ $group_key . '_' . $field_key ] = stripslashes_deep( $field ); | |
} | |
} | |
} | |
return $options; | |
} | |
return false; | |
} | |
function get_saved_meta_option() { | |
global $post; | |
$keys = @get_post_custom_keys( $post->ID ); | |
if( is_array($keys) ) { | |
foreach ( $keys as $key ) { | |
$metas[ preg_replace('/_/', '', $key, 1) ] = get_post_meta( $post->ID, $key, true ); | |
} | |
return $metas; | |
} | |
return false; | |
} | |
function select( $option ) { | |
$value = $this->value($option); | |
$toggle = ( isset($option['toggle']) ) ? ' toggle="' . $this->toggle($option) . '"' : ''; | |
if( isset( $option['source']['pageslider']) ) { | |
$meta = get_post_meta( get_the_ID(), 'AMTA_pageslider', true); //in case it is a post/page option | |
$meta = get_option('AMTA_pageslider', true); //in case it is a theme option | |
require 'pageslider.php'; | |
$pagesliders = array_merge($revsliders, $smartsliders); | |
foreach( $pagesliders as $pageslider ) { | |
$source[ $pageslider->title ] = $pageslider->title; | |
$checked=""; | |
if($pageslider->title == $meta) $checked="selected"; | |
} | |
echo '</select>'; | |
} | |
?> | |
<?php | |
// | |
// The contents of pageslider.php | |
// | |
// Query the database for all Revolution sliders as long as the [rev_slider] shortcode exists | |
// Returns an object array. To use a different plugin, change shortcode and table name, but these need to be accounted for in stack-page_content_home too | |
// Title is used here for UX while editing pages, as it matches what's entered in the plugin area | |
function get_revsliders($output_type=OBJECT) { | |
if( shortcode_exists('rev_slider') ){ | |
global $wpdb; | |
return $wpdb->get_results("SELECT * FROM wp_revslider_sliders", OBJECT); | |
} | |
} | |
// Create workable array out of results | |
$revsliders = get_revsliders(); | |
// Query the database for all Smart Slider 3 sliders as long as the shortcode exists | |
function get_smartsliders($output_type=OBJECT) { | |
if( shortcode_exists('smartslider3' ) ){ | |
global $wpdb; | |
return $wpdb->get_results("SELECT * FROM wp_nextend2_smartslider3_sliders", $output_type); | |
} | |
} | |
$smartsliders = get_smartsliders(); | |
?> | |
<?php | |
// | |
// The content area in stack-page_content_home.php | |
// | |
$pageslider_alias = get_post_meta( get_the_ID(), '_general_pageslider_alias', true ); // _general_slider_alias | |
?> | |
<div class="stack-pageslider-container" id="<?php echo $pageslider_alias; ?>"> | |
<div class="pageslider" id="<?php echo $pageslider_alias; ?>" > | |
<?php | |
// If the slider alias value from the page option meta matches the title of an object in the array of either revsliders or smartsliders, place that slider onto the page. Uncomment the echo's to see the full array of objects. | |
require THEME_FUNCTIONS_DIR . '/pageslider.php'; | |
$pageslider_alias = get_post_meta( get_the_ID(), '_general_pageslider_alias', true ); | |
if(shortcode_exists('rev_slider')) { | |
foreach($revsliders as $revslider){ | |
if(isset($revslider->title) && $revslider->title == $pageslider_alias) { | |
// echo $pageslider_alias . ' is a Revolution Slider! The alias is: ' . $revslider->alias . '! <br/>' . var_dump($revsliders); | |
putRevSlider("$revslider->alias"); } } } | |
if( shortcode_exists('smartslider3' ) ){ | |
foreach($smartsliders as $smartslider){ | |
if(isset($smartslider->title) && $smartslider->title == $pageslider_alias) { | |
// echo $pageslider_alias . ' is a Smart Slider! <br/>' . var_dump($smartsliders); | |
echo do_shortcode('[smartslider3 slider="' . $smartslider->id . '"]'); | |
} } }; | |
?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment