Skip to content
This repository has been archived by the owner. It is now read-only.

Sticky nav and breadcrumbs #146

Merged
merged 1 commit into from Dec 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions functions.php
Expand Up @@ -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 '<ol class="breadcrumb">';

if (wp_get_nav_menu_object('precrumbs')){
$defaults = array(
'menu' => 'Precrumbs',
'container' => false,
'items_wrap' => '%3$s',
'depth' => 1,
'fallback_cb' => false
);
wp_nav_menu( $defaults );
}

foreach ($ancestors as &$ancestor) {
$ancestor_link = get_permalink($ancestor);
$ancestor_title = get_the_title($ancestor);
echo '<li><a href="'.$ancestor_link.'">'.$ancestor_title.'</a></li>';
}
echo '<li class="active">'.get_the_title().'</li>';
echo '</ol>';
}
}

function uc_redirect_403() {
if( get_query_var( 'is_403' ) == true ){
global $wp_query;
Expand Down
38 changes: 38 additions & 0 deletions inc/customizer-nav.php
Expand Up @@ -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)?
)
);



Expand All @@ -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'
)
)
);
};


Expand Down
4 changes: 4 additions & 0 deletions inc/scripts-and-styles.php
Expand Up @@ -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' );
Expand Down
33 changes: 33 additions & 0 deletions 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());
});
});