From 3c8c39c496413e1320ee4bef9b862eb5f6c035ca Mon Sep 17 00:00:00 2001 From: Roy Date: Tue, 20 Dec 2016 14:52:36 -0500 Subject: [PATCH] Sticky nav and breadcrumbs --- functions.php | 33 +++++++++++++++++++++++++++++++++ inc/customizer-nav.php | 38 ++++++++++++++++++++++++++++++++++++++ inc/scripts-and-styles.php | 4 ++++ js/stickynav.js | 33 +++++++++++++++++++++++++++++++++ 4 files changed, 108 insertions(+) create mode 100644 js/stickynav.js diff --git a/functions.php b/functions.php index 7ea796d..ede87cf 100644 --- a/functions.php +++ b/functions.php @@ -247,6 +247,39 @@ function ssi_add_widget_class( $classes ) { return $classes; } +function cornerstone_breadcrumbs(){ + if(get_option('breadcrumbs') != 'on') { + return; + } + $thisID = get_the_ID(); + $ancestors = get_ancestors($thisID, 'page'); + $ancestors = array_reverse($ancestors); + + + if ($ancestors) { + echo ''; + } +} + function uc_redirect_403() { if( get_query_var( 'is_403' ) == true ){ global $wp_query; diff --git a/inc/customizer-nav.php b/inc/customizer-nav.php index 8143cc6..81efa8e 100644 --- a/inc/customizer-nav.php +++ b/inc/customizer-nav.php @@ -7,6 +7,22 @@ $wp_customize->add_setting( 'navoption1', //Give it a SERIALIZED name (so all th 'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)? ) ); +$wp_customize->add_setting( 'stickynav', //Give it a SERIALIZED name (so all theme settings can live under one db record) + array( + 'default' => 'off', //Default setting/value to save + 'type' => 'option', //Is this an 'option' or a 'theme_mod'? + 'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting. + 'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)? + ) +); +$wp_customize->add_setting( 'breadcrumbs', //Give it a SERIALIZED name (so all theme settings can live under one db record) + array( + 'default' => 'off', //Default setting/value to save + 'type' => 'option', //Is this an 'option' or a 'theme_mod'? + 'capability' => 'edit_theme_options', //Optional. Special permissions for accessing this setting. + 'transport' => 'refresh', //What triggers a refresh of the setting? 'refresh' or 'postMessage' (instant)? + ) +); @@ -33,6 +49,28 @@ if (!$maxMegaMenuActive){ ) ) ); + + $wp_customize->add_control('stickynav', array( + 'type' => 'radio', + 'label' => 'Sticky Navigation', + 'section' => 'nav', + 'choices' => array( + 'on'=>'On', + 'off'=>'Off' + ) + ) + ); + + $wp_customize->add_control('breadcrumbs', array( + 'type' => 'radio', + 'label' => 'Breadcrumbs', + 'section' => 'nav', + 'choices' => array( + 'on'=>'On', + 'off'=>'Off' + ) + ) + ); }; diff --git a/inc/scripts-and-styles.php b/inc/scripts-and-styles.php index e74d5d0..a8626c1 100644 --- a/inc/scripts-and-styles.php +++ b/inc/scripts-and-styles.php @@ -26,6 +26,10 @@ function cs_scripts() { if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) { wp_enqueue_script( 'comment-reply' ); } + + if(get_option('stickynav') == 'on') { + wp_enqueue_script( 'stickynav', get_template_directory_uri() . '/js/stickynav.js', array( 'jquery' )); + } } add_action( 'wp_enqueue_scripts', 'cs_scripts' ); diff --git a/js/stickynav.js b/js/stickynav.js new file mode 100644 index 0000000..5fbbcad --- /dev/null +++ b/js/stickynav.js @@ -0,0 +1,33 @@ +jQuery(document).ready(function( $ ) { + $(window).on("load scroll resize", function() { + var elem = $('#nav-wrapper'); + if (!elem.attr('data-top')) { + if (elem.hasClass('navbar-fixed-top')) + return; + var offset = elem.offset(); + elem.attr('data-top', offset.top - $('#wpadminbar').outerHeight()); + } + if (elem.attr('data-top') - elem.outerHeight() <= $(this).scrollTop() - $(elem).outerHeight()){ + elem.addClass('navbar-fixed-top'); + elem.css('padding-top',$('#wpadminbar').outerHeight()); + } + else { + elem.removeClass('navbar-fixed-top'); + elem.css('padding-top','0'); + } + + if ($('#nav-wrapper').hasClass('navbar-fixed-top')){ + $('.site-content').css('padding-top' , $('#nav-wrapper').height()); + } + + else { + $('.site-content').css('padding-top' ,'0px'); + } + }); + + $(window).on("resize", function() { + var elem = $('#nav-wrapper'); + var offset = $('#site-title').offset().top + $('#site-title').outerHeight(); + elem.attr('data-top', offset - $('#wpadminbar').outerHeight()); + }); +}); \ No newline at end of file