Skip to content

Instantly share code, notes, and snippets.

@KinnaT
Last active May 3, 2016 19:36
Show Gist options
  • Save KinnaT/a2971b824d76aff8f5e7f058a525a9b7 to your computer and use it in GitHub Desktop.
Save KinnaT/a2971b824d76aff8f5e7f058a525a9b7 to your computer and use it in GitHub Desktop.
Functional selectable sliders as page meta option, uncommented version - accounts for the Revolution Slider and Smart Slider 3 plugins, trivial to add support for more plugins
<?php
// content.php
$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);
?>
<?php
// 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
// pageslider.php
function get_revsliders($output_type=OBJECT) {
if( shortcode_exists('rev_slider') ){
global $wpdb;
return $wpdb->get_results("SELECT * FROM wp_revslider_sliders", OBJECT);
}
}
$revsliders = get_revsliders();
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
// 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
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) {
putRevSlider("$revslider->alias"); } } }
if( shortcode_exists('smartslider3' ) ){
foreach($smartsliders as $smartslider){
if(isset($smartslider->title) && $smartslider->title == $pageslider_alias) {
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