Skip to content

Instantly share code, notes, and snippets.

@papacasper
Forked from danielpataki/add-section.php
Last active June 4, 2019 17:48
Show Gist options
  • Save papacasper/4249ba15f3936a531ffd157e4f61a070 to your computer and use it in GitHub Desktop.
Save papacasper/4249ba15f3936a531ffd157e4f61a070 to your computer and use it in GitHub Desktop.

Revisions

  1. Daniel Pataki revised this gist Jan 11, 2017. 4 changed files with 50 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions photocount-ui.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <div id='photocount'>
    <span><?php echo get_theme_mod( 'cd_photocount', 0 ) ?></span> photos
    </div>
    12 changes: 12 additions & 0 deletions range-control.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    $wp_customize->add_setting( 'cd_photocount' , array(
    'default' => 0,
    'transport' => 'postMessage',
    ) );

    $wp_customize->add_control( new WP_Customize_Range( $wp_customize, 'cd_photocount', array(
    'label' => 'Photo Count',
    'min' => 10,
    'max' => 9999,
    'step' => 10,
    'section' => 'title_tagline',
    ) ) );
    5 changes: 5 additions & 0 deletions range.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    wp.customize( 'cd_photocount', function( value ) {
    value.bind( function( newval ) {
    $( '#photocount span' ).html( newval );
    } );
    } );
    30 changes: 30 additions & 0 deletions range.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    if( class_exists( 'WP_Customize_Control' ) ) {
    class WP_Customize_Range extends WP_Customize_Control {
    public $type = 'range';

    public function __construct( $manager, $id, $args = array() ) {
    parent::__construct( $manager, $id, $args );
    $defaults = array(
    'min' => 0,
    'max' => 10,
    'step' => 1
    );
    $args = wp_parse_args( $args, $defaults );

    $this->min = $args['min'];
    $this->max = $args['max'];
    $this->step = $args['step'];
    }

    public function render_content() {
    ?>
    <label>
    <span class="customize-control-title"><?php echo esc_html( $this->label ); ?></span>
    <input class='range-slider' min="<?php echo $this->min ?>" max="<?php echo $this->max ?>" step="<?php echo $this->step ?>" type='range' <?php $this->link(); ?> value="<?php echo esc_attr( $this->value() ); ?>" oninput="jQuery(this).next('input').val( jQuery(this).val() )">
    <input onKeyUp="jQuery(this).prev('input').val( jQuery(this).val() )" type='text' value='<?php echo esc_attr( $this->value() ); ?>'>

    </label>
    <?php
    }
    }
    }
  2. Daniel Pataki revised this gist Jan 11, 2017. 6 changed files with 28 additions and 0 deletions.
    10 changes: 10 additions & 0 deletions button-text-control.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    $wp_customize->add_setting( 'cd_button_text' , array(
    'default' => 'Come On In',
    'transport' => 'postMessage',
    ) );

    $wp_customize->add_control( 'cd_button_text', array(
    'label' => 'Button Text',
    'section' => 'cd_button',
    'type' => 'text',
    ) );
    5 changes: 5 additions & 0 deletions button-text-preview.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    wp.customize( 'cd_button_text', function( value ) {
    value.bind( function( newval ) {
    $( '#intro a' ).html( newval );
    } );
    } );
    1 change: 1 addition & 0 deletions button-text.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    <a href="" class='button'><?php echo get_theme_mod( 'cd_button_text', 'Come On In' ) ?></a>
    3 changes: 3 additions & 0 deletions button.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <div id='button-container'>
    <?php cd_show_main_button() ?>
    </div>
    5 changes: 5 additions & 0 deletions partials.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    function cd_show_main_button() {
    if( get_theme_mod( 'cd_button_display', 'show' ) == 'show' ) {
    echo "<a href='' class='button'>" . get_theme_mod( 'cd_button_text', 'Come On In' ) . "</a>";
    }
    }
    4 changes: 4 additions & 0 deletions selective-refresh.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    $wp_customize->selective_refresh->add_partial( 'cd_button_display', array(
    'selector' => '#button-container',
    'render_callback' => 'cd_show_main_button',
    ) );
  3. Daniel Pataki revised this gist Jan 11, 2017. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions button-condition.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    <?php if( get_theme_mod( 'cd_button_display', 'show' ) == 'show' ) : ?>
    <a href="" class='button'>Come On In</a>
    <?php endif ?>
  4. Daniel Pataki revised this gist Jan 11, 2017. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions button-control.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    $wp_customize->add_section( 'cd_button' , array(
    'title' => 'The Button',
    'priority' => 20,
    ) );

    $wp_customize->add_setting( 'cd_button_display' , array(
    'default' => true,
    'transport' => 'refresh',
    ) );

    $wp_customize->add_control( 'cd_button_display', array(
    'label' => 'Button Display',
    'section' => 'cd_button',
    'settings' => 'cd_button_display',
    'type' => 'radio',
    'choices' => array(
    'show' => 'Show Button',
    'hide' => 'Hide Button',
    ),
    ) );
  5. Daniel Pataki revised this gist Jan 11, 2017. 1 changed file with 11 additions and 0 deletions.
    11 changes: 11 additions & 0 deletions changing-identity.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,11 @@
    wp.customize( 'blogname', function( value ) {
    value.bind( function( newval ) {
    $( '#intro h1' ).html( newval );
    } );
    } );

    wp.customize( 'blogdescription', function( value ) {
    value.bind( function( newval ) {
    $( '#intro h2' ).html( newval );
    } );
    } );
  6. Daniel Pataki revised this gist Jan 11, 2017. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions default-transport.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    $wp_customize->get_setting( 'blogname' )->transport = 'postMessage';
    $wp_customize->get_setting( 'blogdescription' )->transport = 'postMessage';
  7. Daniel Pataki revised this gist Jan 11, 2017. 3 changed files with 22 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions customizer-basic.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,3 @@
    ( function( $ ) {

    } )( jQuery );
    9 changes: 9 additions & 0 deletions customizer.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    ( function( $ ) {

    wp.customize( 'background_color', function( value ) {
    value.bind( function( newval ) {
    $( 'body' ).css( 'background-color', newval );
    } );
    } );

    } )( jQuery );
    10 changes: 10 additions & 0 deletions enqueue.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,10 @@
    add_action( 'customize_preview_init', 'cd_customizer' );
    function cd_customizer() {
    wp_enqueue_script(
    'cd_customizer',
    get_template_directory_uri() . '/customizer.js',
    array( 'jquery','customize-preview' ),
    '',
    true
    );
    }
  8. Daniel Pataki revised this gist Jan 10, 2017. 2 changed files with 10 additions and 1 deletion.
    2 changes: 1 addition & 1 deletion create-control.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'background_color', array(
    'label' => 'Background Color'
    'label' => 'Background Color',
    'section' => 'cd_colors',
    'settings' => 'background_color',
    ) ) );
    9 changes: 9 additions & 0 deletions custom-css.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,9 @@
    add_action( 'wp_head', 'cd_customizer_css');
    function cd_customizer_css()
    {
    ?>
    <style type="text/css">
    body { background: #<?php echo get_theme_mod('background_color', '#43C6E4'); ?>; }
    </style>
    <?php
    }
  9. Daniel Pataki revised this gist Jan 10, 2017. 4 changed files with 17 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions add-section.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    $wp_customize->add_section( 'cd_colors' , array(
    'title' => 'Colors',
    'priority' => 30,
    ) );
    5 changes: 5 additions & 0 deletions create-control.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    $wp_customize->add_control( new WP_Customize_Color_Control( $wp_customize, 'background_color', array(
    'label' => 'Background Color'
    'section' => 'cd_colors',
    'settings' => 'background_color',
    ) ) );
    4 changes: 4 additions & 0 deletions create-setting.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    $wp_customize->add_setting( 'background_color' , array(
    'default' => '#43C6E4',
    'transport' => 'refresh',
    ) );
    4 changes: 4 additions & 0 deletions customizer-basics.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,4 @@
    add_action( 'customize_register', 'cd_customizer_settings' );
    function cd_customizer_settings( $wp_customize ) {

    }
  10. Daniel Pataki created this gist Jan 10, 2017.
    1 change: 1 addition & 0 deletions functions-include.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    include('customizer.php');